JOIN us on
WhatsApp Group Join Now
Telegram Join Join Now

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

Categories: C Language in hindi

String : Advance Methodology in c language in hindi स्ट्रिंग क्या है c कंप्यूटर भाषा में

स्ट्रिंग क्या है c कंप्यूटर भाषा में String : Advance Methodology in c language in hindi :-
हमने पिछले आर्टिकल्स मे , string.h के कुछ महत्वपूर्ण function
का study किया |अब हम string.h header file के कुछ अन्य function,string coping,string
comparing,string cascading को को पड़गे |
1.Strncpy()
strcpy() का use एक string को दूसरी string मे copy करने
के लिए किया जाता है और strncpy() का used किसी string के छोटे से portion को दुसरे
string मे copy करने के लिए किया जाता है |इसका syntax है :-

 

strncpy(string_name 1,string_name 2,N);

 

ये तीन parameter function है |जिसमे

 

string_name 1: उस string का नामे है जिसमे portion copy होगा
|

 

string_name 2: उस string का नाम होता है जिसमे से
portion को लिया जाता है |

 

N : character का number है जो string_name 2 से copy होगे
|

 

उदहारण के लिए :

 

#include<conio.h>

 

#include<stdio.h>

 

#include<string.h>

 

Void main(0

 

{

 

char first_name[15]=”Parth Patel”;

 

Char last_name[10]=”Rahul”;

 

Strncpy(first_name,last_name,5);

 

Printf(“%s”, first_name);

 

getch();

 

}
आउटपुट होगा :

 

Rahul Patel
इस उदाहरण मे , string 2 मे से Rahul string 1 मे left side से पांच position पर copy हो जाता है |
Strncmp()
Strncmp() का use एक string को दूसरी string से compare करने के लिए किया जाता है और Strncmp () का used किसी string के छोटे से portion को दुसरे string के छोटे से portion  से compare करने के लिए किया जाता है |इसका syntax है :-
Strncmp (string_name 1,string_name 2,N);
ये तीन parameter function है |जिसमे
string_name 1: उस string का नाम है |
string_name 2: उस string का नाम होता है ||
N : character का number है जिन्हें compare करना है|
अगर compare करने के बाद:
1.match होने पर आउटपुट 0 मिलेगे|
2.अगर string_name 1 < string_name 1 है तो आउटपुट नेगेटिव मिलेगे |
3.अगर string_name 1 > string_name 1 है तो आउटपुट पॉजिटिव मिलेगे |
उदहारण के लिए :

 

#include<conio.h>

 

#include<stdio.h>

 

#include<string.h>

 

Void main(0

 

{

 

char first_name[15]=”Patel Parth”;

 

Char last_name[15]=”Patel Rahul”;

 

if(Strncmp(first_name,last_name,5)==0)
{

 

Printf(“first five charterer are same. “);
}
else
{
Printf(“first five charterer are not same. “);
}

 

getch();
}
आउटपुट होगा :
first five charterer are same.
Strncat()
Strncat() का use एक string को दूसरी string के आगे जोड़ने के लिए किया जाता है और Strncmp () का used किसी string के छोटे से portion को दुसरे string के के age जोड़ने के लिए किया जाता है |इसका syntax है :-
Strncat (string_name 1,string_name 2,N);
ये तीन parameter function है |जिसमे
string_name 1: उस string का नाम है |जिसके आगे string का portion जोड़ा जायेगा |
string_name 2: उस string का नाम होता है जिसमे से portion को लिया जायेगा
N : character का number है जिन्हें जोड़ा जायेगा|
string_name 1 की size इंतनी होनी चाहिए की उसमे string_name 2 का portion add हो जाये |
उदाहरण के लिए:
#include<conio.h>
#include<stdio.h>
#include<string.h>
Void main(0
{
char first_name[15]=”Parth”;
char last_name[15]=”Patel Rahul”;
Printf(“%s”, first_name);
Strncat(first_name,last_name,5);
Printf(“%s”, first_name);
getch();
}
आउटपुट होगा :
Parth
Parth Patel
Strstr()
ये function का कार्य है किसी string मे से किसी string को search करना |इसका syntax है :
strstr(string_name 1,string_name 2);
ये दो parameter function है जिसमे string_name 2 को string_name 1 मे search किया जायेगा |अगर string_name 2 ,string_name 1 मे मिल जाता है तब function ,उस character की position को return करेगे जहा से string_name 2 ,string_name 1 मे start होता  है |
अगर नहीं मिलता है तब null pointer return करेगा |
उदहारण के लिए :
#include<conio.h>

 

#include<stdio.h>

 

#include<string.h>

 

Void main(0

 

{

 

char first_string[15]=”Good Morning!”;

 

Char last_string[15]=”Good”;

 

if(Strstr(first_string,last_string)==Null)
{

 

Printf(“ last_string is not found in first_string “);
}
else
{
Printf(“last_string is found in first_string.”);
}

 

getch();

 

}
आउटपुट होगा :
last_string is found in first_string.
इस function मे string_name 2 मे कोई constant को pass करा सकते है |
जैसे

 

#include<conio.h>

 

#include<stdio.h>
#include<string.h>
Void main(0
{
char first_string[15]=”Good Morning!”;
if(Strstr(first_string,P)==Null)
{
Printf(“ P is not found in first_string. “);
}
else
{
Printf(“ P is found in first_string.”);
}
getch();
}
यहा पर string_name 2 मे ‘P’ केवल pass किया गया है |
आउटपुट होगा :
P is not found in first_string.

String Comparison:

हमने strings comparison के strcmp() और strncmp () को study किया लेकिन इसी function को अगर for loop से बनाना हो तो इसका प्रोग्रम्मे है नीचे है |
#incluide<conio.h>
#include<stdio.h>
#define size 10
void main()
{
char a[size]=”Parth”;
char b[size]=”Meet”;
int i;
int j=0;
for(i=0;i<=size;i++)
{
if(a[i]==b[i])
{
j=j+1;
}
else
{
j=0;
break;
}
if(j==size)
{
printf(“both string are same.”);
}
else
{
printf(“Both string are not same.”);
}
}
जब i=0 ,तब a[0] और b[0] compare होगे ,same होने पर j की value increment होगा |
जब i=1 ,तब a[1] और b[1] compare होगे ,same होने पर j की valueफिर से  increment होगा |
जब i=2 ,तब a[2] और b[2] compare होगे ,same होने पर j की value increment होगा |
इस तरह से , for loop string की size के हिसाब से execute होगा |सभी string character same होने पर j की value और size same हो जाएगी|
अगर किसी भी position पर strings की value same न होने पर j की value 0 set हो जाएगी और for loop break हो जायेगा|

String length calculation :

अगर strlen() function का inner प्रोग्राम कैसे execute होगा |इसके लिए नीचे वाले प्रोग्राम को स्टडी करे |
#include<conio.h>
#include<stdio.h>
#define size 45
vopid main()
{
char a[size]=”Parth Patel”;
int i,length;
for(i=0;i<=size;i++)
{
if(a[i]!=’/0′)
{
length=length+1;
}
else
{
break;
}
printf(“Length of string=%d”,length);
}
इस code की working, strings comparison के code की तरह है परन्तु इसमें string character को null ‘/0’ से checkकी जाती है |क्योकि string का आखरी character null होता है |
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