हिंदी माध्यम नोट्स
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++;
alpha++;
}
else
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)
if(check!=0)
{
i=0;
i=0;
while (statement[i+check]==’\n’)
{
statement[i]=statement[i+check];
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++;
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
Recent Posts
सती रासो किसकी रचना है , sati raso ke rachnakar kaun hai in hindi , सती रासो के लेखक कौन है
सती रासो के लेखक कौन है सती रासो किसकी रचना है , sati raso ke…
10 hours ago
मारवाड़ रा परगना री विगत किसकी रचना है , marwar ra pargana ri vigat ke lekhak kaun the
marwar ra pargana ri vigat ke lekhak kaun the मारवाड़ रा परगना री विगत किसकी…
10 hours ago
राजस्थान के इतिहास के पुरातात्विक स्रोतों की विवेचना कीजिए sources of rajasthan history in hindi
sources of rajasthan history in hindi राजस्थान के इतिहास के पुरातात्विक स्रोतों की विवेचना कीजिए…
2 days ago
गुर्जरात्रा प्रदेश राजस्थान कौनसा है , किसे कहते है ? gurjaratra pradesh in rajasthan in hindi
gurjaratra pradesh in rajasthan in hindi गुर्जरात्रा प्रदेश राजस्थान कौनसा है , किसे कहते है…
2 days ago
Weston Standard Cell in hindi वेस्टन मानक सेल क्या है इससे सेल विभव (वि.वा.बल) का मापन
वेस्टन मानक सेल क्या है इससे सेल विभव (वि.वा.बल) का मापन Weston Standard Cell in…
3 months ago
polity notes pdf in hindi for upsc prelims and mains exam , SSC , RAS political science hindi medium handwritten
get all types and chapters polity notes pdf in hindi for upsc , SSC ,…
3 months ago