JOIN us on
WhatsApp Group Join Now
Telegram Join Join Now

हिंदी माध्यम नोट्स

Categories: C Language in hindi

String : Advance Examples (Part 2) in c language in hindi , some string example in advance level

some string example in advance level , String : Advance Examples (Part 2) in c language in hindi :-
String : Advance Examples (Part 1) मे हमने string related कुछ advance उदाहरन को देखा था |अब इस article मे , string के कुछ और advance उदाहरण को देखेगे जिससे की string के concept को अच्छी तरह से समजा सके |
उदाहरण 1:
Write a program to copy a string into other string (Without strcmp () function ) .
इस उदहारण मे , एक string को किसी और string मे copy करने करना है लेकिन string के standard function strcmp() का use नहीं करना है |
Explanation
1.सबसे पहले , एक string variable ‘statement’ को declare करगे | और यूजर द्वारा दिए गये input को इस string assign करेगे |
2. उसके बाद string की length को strlen() function से calculate करते हैऔर इसे length मे assign करते है |
3.उसके बाद एक दूसरी string ‘output’ को declare करते है जिसमे string को copy करना है |
3.उसके बाद , copy() को call करगे जिसमे statement और output को pass करते है  |इसमें function को call by reference से भुलाया जाता है |
copy() ,
1.सबसे पहले , strlen() से string ‘statement’ की size को calculate कर लेते है |
2.looping होती है |loop तब तक चलता है जब तक ‘statement’ मे null pointer नहीं आ जाता है |
loop मे ,
2.1- ‘statement[i] की value को output [i] पर assign कर देते है |
3. जब loop terminate हो जाता है तब string output के length+1 position पर null pointer assign कर देते है |
Source Code
#include<stdio.h>
#include<conio.h>
#include<string.h>
void copy (char * , char *);
void main ()
{
char statement[100];
printf(“Enter String “);
scanf(“%s”, statement);
char output [100];
copy(statement , output );
printf(“Copied String Value \n”)
printf(“%s”, output );
getch();
}
void copy(char *s , char *c)
{
int length= strlen(s);
int i;
for(i=0;i<length;i++)

 

{
c[i]=s[i];

 

}
c[length+1]=’\0′;
}
आउटपुट होगा :
Enter String parth
Copied String Value
parth
उदाहरण 2:
Write a program to calculate number of alphabets , digit or special character in string .
इस उदहारण मे , कसी string मे से character , डिजिट और special character के number को find आउट करना होता है |
Explanation
1.सबसे पहले , एक string variable ‘statement’ को declare करगे | और यूजर द्वारा दिए गये input को इस string assign करेगे |
2. उसके बाद string की length को strlen() function से calculate करते हैऔर इसे length मे assign करते है |
3. loop चलाया जाता है |loop तब तक चलता है जब तक की string मे null pointer नहीं आ जाता है |
3.i. condition check की जाती है |
अगर charterer ‘alphabets’ है तब alpha मे increment होगा |
अगर character ‘digit ‘ है तब count मे increment होगा |
और character ‘special character ‘ होता है तब ‘s’ मे increment होगा|
Source Code
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main ()
{
char statement[100];
printf(“Enter String “);
gets(statement);
int alpha =0;
int s=0;
int count=0;
int length = strlen(statement);
for(i=0;i<length;i++)
{
if(statement[i]=’/0′ && statement[i]== ‘ ‘ )
{
s++;
}
elseif(statement[i] >=’0′ && statement[i] <= ‘9’)
{
count++;
}
elseif((statement[i] >=’a’ && statement[i] <= ‘z’)|| (statement[i] >=’A’ && statement[i] <= ‘Z’))
{
alpha++;
}
else
{
;
}
printf(“Number of Character = %d \n”, alpha ) ;
printf(“Number of Digit  = %d\n “, digit ) ;
printf(“Number of Special Character  = %d \n “, s ) ;
getch();
}
आउटपुट होगा :
Enter String parth4546@
Number of Character = 5
Number of Digit = 4
Number of Special Character  = 1
उदाहरण 3:
Write a program to eliminate leading blank space in string
इस उदहारण मे , किसी string के पहले आने वाले वाले blank space को eliminate करना है |
Explanation
1.सबसे पहले , एक string variable ‘statement’ को declare करगे | और यूजर द्वारा दिए गये input को इस string assign करेगे |
2. उसके बाद string की length को strlen() function से calculate करते हैऔर इसे length मे assign करते है |
3.सबसे पहले string मे स्थित white space को calculate किया जाता है |
4 loop मे ,  condition check की जाती है |
अगर string का first character ‘space’ है तब string के सभी character left side मूव हो जाते है |
4. ये condition तब  तक चलती है जब तक string के first character blank space नहीं हो जाता है |
Source Code
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main ()
{
char statement[100];
printf(“Enter String : “);
gets(statement);
int i,j,check;
int length = strlen(statement);
check=0;
while (statement[check]=’ ‘ && statement[check] == ‘\t’ && statement[check] == ‘\n’  )
{
check++;
}
if(check!=0)
{
i=0;
while (statement[i+check]==’\n’)
{
statement[i]=statement[i+check];
i++;
}
statement[i]=’/0′;
}
printf(“string without forward space”);
puts(statement);
getch();
}
आउटपुट होगा :
Enter String :        parth
string without forward space :parth
उदाहरण 4:
Write a program to eliminate trailing blank space in string
इस उदहारण मे , किसी string के बाद आने वाले वाले blank space को eliminate करना है |
Explanation
1.सबसे पहले , एक string variable ‘statement’ को declare करगे | और यूजर द्वारा दिए गये input को इस string assign करेगे |
2. उसके बाद string की length को strlen() function से calculate करते हैऔर इसे length मे assign करते है |
3.इस प्रोग्राम मे , null pointer के position को set करनी है
Source Code
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main ()
{
char statement[100];
printf(“Enter String : “);
gets(statement);
int i,j,check;
int length = strlen(statement);
i=0;
check=-1;
while(statement[i]=’ ‘ && statement[i] == ‘\t’ && statement[i] == ‘\n’)
{
check=i;
}
i++;
}
statement[check+1] = ‘\0’;
printf(“string without backward space”);
puts(statement);
getch();
}
आउटपुट होगा :
Enter String :parth         /0
string without backward space :parth/0
उदाहरण 5:
Write a program to calculate number of consonant और vowel character in string .
इस उदहारण मे , कसी string मे से consonant और vowel character के number को find आउट करना होता है |
Explanation
1.सबसे पहले , एक string variable ‘statement’ को declare करगे | और यूजर द्वारा दिए गये input को इस string assign करेगे |
2. उसके बाद string की length को strlen() function से calculate करते हैऔर इसे length मे assign करते है |
3. loop चलाया जाता है |loop तब तक चलता है जब तक की string मे null pointer नहीं आ जाता है |
3.i. condition check की जाती है |
अगर charterer ‘consonant’ है तब ‘c’ मे increment होगा |
अगर character ‘vowel ‘ है तब ‘v’ मे increment होगा |
Source Code
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main ()
{
char statement[100];
printf(“Enter String “);
gets(statement);
int c =0;
int v=0;
int length = strlen(statement);
for(i=0;i<length;i++)
{
if( statement[i] >=’a’ || statement[i] >=’e’ || statement[i] >=’i’ || statement[i] >=’o’ || statement[i] >=’u’
statement[i] >=’A’  || statement[i] >=’E’ || statement[i] >=’O’ || statement[i] >=’U’ || statement[i] >=’I’ );
{
v++;
}
else
{
c++;
}
}
printf(“Number of Consonant = %d \n”, c ) ;
printf(“Number of Vowels  = %d\n “, v ) ;
getch();
}
आउटपुट होगा :
Enter String parthpatel
Number of Consonant = 3
Number of Vowels  = 7
Sbistudy

Recent Posts

Question Tag Definition in english with examples upsc ssc ias state pcs exames important topic

Question Tag Definition • A question tag is a small question at the end of a…

2 weeks ago

Translation in english grammer in hindi examples Step of Translation (अनुवाद के चरण)

Translation 1. Step of Translation (अनुवाद के चरण) • मूल वाक्य का पता करना और उसकी…

2 weeks ago

Report Writing examples in english grammer How to Write Reports explain Exercise

Report Writing • How to Write Reports • Just as no definite rules can be laid down…

2 weeks ago

Letter writing ,types and their examples in english grammer upsc state pcs class 12 10th

Letter writing • Introduction • Letter writing is an intricate task as it demands meticulous attention, still…

2 weeks ago

विश्व के महाद्वीप की भौगोलिक विशेषताएँ continents of the world and their countries in hindi features

continents of the world and their countries in hindi features विश्व के महाद्वीप की भौगोलिक…

2 weeks ago

भारत के वन्य जीव राष्ट्रीय उद्यान list in hin hindi IAS UPSC

भारत के वन्य जीव भारत में जलवायु की दृष्टि से काफी विविधता पाई जाती है,…

2 weeks ago
All Rights ReservedView Non-AMP Version
X

Headline

You can control the ways in which we improve and personalize your experience. Please choose whether you wish to allow the following:

Privacy Settings
JOIN us on
WhatsApp Group Join Now
Telegram Join Join Now