C String Functions - .OnlineGuruji

.OnlineGuruji

Provides E-Notes,Video Tutorials And Download Links For Students In hindi

*********************************************************

*********************************************************
********************************************************************************

Breaking

Ramchandicollege Saraipali

Technology Jobs

OnlineGuru Blog मे आपका स्वागत है ब्लॉग से संबन्धित जानकारी के लिए संपर्क करें मो ॰ नम ।-9826026747(सपन कुमार दास) अपने विषय से संबन्धित अपडेट प्राप्त करने के लिए ब्लॉग पे दिये गए Bell Icon को press करें कम्प्युटर,Science,English Grammer से संबन्धित विषय की अधिक जानकारी के लिए हमारे ब्लॉग अथवा यू ट्यूब चैनल को सब्क्राइब करे ..

Friday, November 28, 2025

C String Functions

 


C String Functions

C लैंग्वेज में कई बिल्ट-इन फ़ंक्शन होते हैं जिनका इस्तेमाल स्ट्रिंग पर अलग-अलग ऑपरेशन और मैनिपुलेशन के लिए किया जा सकता है। ये स्ट्रिंग फ़ंक्शन स्ट्रिंग कॉपी, कंकैटनेशन, कम्पेरिजन, लेंथ वगैरह जैसे काम करना आसान बनाते हैं। <string.h> हेडर फ़ाइल में ये स्ट्रिंग फ़ंक्शन होते हैं।

1-strlen()

strlen() फ़ंक्शन का इस्तेमाल स्ट्रिंग की लेंथ पता करने के लिए किया जाता है। यह स्ट्रिंग में कैरेक्टर की संख्या बताता है, जिसमें नल टर्मिनेटर ('\0') शामिल नहीं है।

उदाहरण

#include <stdio.h>

#include <string.h>

#include <conio.h>

void main() {

    char s[] = "sapan          ";

   clrscr();

                // Finding and printing length of string s

    printf("%d", strlen(s));

getch();

}

S2-trcpy()

strcpy() फ़ंक्शन सोर्स से डेस्टिनेशन तक एक स्ट्रिंग कॉपी करता है. यह नल टर्मिनेटर सहित पूरी स्ट्रिंग कॉपी करता है.

 

उदाहरण:

#include <stdio.h>

#include <string.h>

#include <conio.h>

 

void main()

 {

   char src[] = "Hello";

    char dest[20];

   

    // Copies "Hello" to dest

    strcpy(dest, src); 

    printf("%s", dest);

   

getch();

}

3-strncpy()

strncpy() फ़ंक्शन strcpy() जैसा ही है, लेकिन यह सोर्स से डेस्टिनेशन स्ट्रिंग में ज़्यादा से ज़्यादा n बाइट्स कॉपी करता है। अगर सोर्स n से छोटा है, तो strncpy() डेस्टिनेशन में एक नल कैरेक्टर जोड़ता है ताकि यह पक्का हो सके कि n कैरेक्टर लिखे गए हैं।

 

उदाहरण:

#include <stdio.h>

#include <string.h>

#include <conio.h>

 

void main()

 {

   char src[] = "Hello";

    char dest[20];

   

    // Copies "Hello" to dest

    strncpy(dest, src, 4);

    printf("%s", dest);

getch();

}

4-strcat()

strcat() फ़ंक्शन का इस्तेमाल एक स्ट्रिंग को दूसरी स्ट्रिंग के आखिर में जोड़ने (जोड़ने) के लिए किया जाता है। यह सोर्स स्ट्रिंग को डेस्टिनेशन स्ट्रिंग में जोड़ता है, और डेस्टिनेशन के नल टर्मिनेटर को सोर्स स्ट्रिंग के कंटेंट से बदल देता है।

 

उदाहरण

#include <stdio.h>

#include <string.h>

#include <conio.h>

 

void main()

 {

    char s1[30] = "Sapan ";

    char s2[] = "Das";

    clrscr();

    // Appends "Geeks!" to "Hello, "

    strcat(s1, s2); 

    printf("%s", s1);

   

getch();

 

 

5-strncat()

C में, strcat() जैसा ही एक फ़ंक्शन strncat() होता है। यह फ़ंक्शन सोर्स से पॉइंट किए गए स्ट्रिंग से डेस्टिनेशन से पॉइंट किए गए स्ट्रिंग के आखिर में n से ज़्यादा कैरेक्टर नहीं जोड़ता है, साथ ही एक टर्मिनेटिंग NULL कैरेक्टर भी जोड़ता है।

 

उदाहरण:

#include <stdio.h>

#include <string.h>

 

int main() {

    char s1[30] = "Hello, ";

    char s2[] = "Geeks!";

   

    // Appends "Geeks!" to "Hello, "

    strncat(s1, s2, 4); 

    printf("%s", s1);

    return 0;

}

 

 

6-strcmp()

strcmp() C में एक बिल्ट-इन लाइब्रेरी फ़ंक्शन है। यह फ़ंक्शन दो स्ट्रिंग को आर्गुमेंट के तौर पर लेता है, इन दो स्ट्रिंग की तुलना लेक्सिकोग्राफ़िकली करता है और तुलना के नतीजे में एक इंटीजर वैल्यू देता है।

 

उदाहरण

#include <stdio.h>

#include <string.h>

#include <conio.h>

 

void main()

 {

     char s1[] = "Apple";

    char s2[] = "Applet";

    clrscr();

                // Compare two strings

                // and print result

    int res = strcmp(s1, s2);

    if (res < 0)

        printf("S1 is smaller than s2");

                else if (res > 0)

                printf("s1 greater than s2");

                else

                printf("both are same length " );

 

 

   

getch();

}

No comments:

Post a Comment