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();
}

Welcome to OnlineGuru2020.blogspot.com, your number one source for all things related to Online Education. We're dedicated to providing you the very best of Digital Education, with an emphasis on E-notes,Download Links in PDF and youtube videos etc
OnlineGuru2020 Founded in [2020] by Sapan Kumar Das (Asst. Proff Ramchandi College Saraipali), OnlineGuru2020.blogspot.com has come a way from its beginnings .When I first started, my passion inspired me to start my own blog, seeing the need for students in lockdown2020
We hope you enjoy our products as much as we enjoy offering them to you. If you have any questions or comments, please don't hesitate to contact us.
Contact Datails:-
Mobile Number:-9826026747
Email:-sapam.online@gmail.com
Sincerely,
Sapan Kumar Das
.
No comments:
Post a Comment