String handling functions strlen, strcpy, strcmp, etc c++ In Hindi

String handling functions strlen, strcpy, strcmp, etc c++ In Hindi

C++ प्रोग्रामिंग लैंग्वेज में std::string बिल्ट-इन फंक्शन लाइब्रेरी के अपोजिट, सी लैंग्वेज या C-स्टाइल करैक्टर डाटा टाइप स्ट्रिंग में append(), length(), या find() जैसे मेंबर फ़ंक्शन अवेलेबल नहीं होते हैं। इसके बदले इसमें, किसी यूजर डिफाइन प्रोग्राम करैक्टर स्ट्रिंग ऐरे को कॉपी करना, करैक्टर स्ट्रिंग को ऐड करना, और करैक्टर स्ट्रिंग को कम्पेयर करना जैसे स्ट्रिंग ऑपरेशन के लिए C लैंग्वेज स्टैंडर्ड लाइब्रेरी फ़ंक्शन का यूज़ करना होता हैं।

String handling functions strlen, strcpy, strcmp, etc c++ In Hindi

String length method in C++.

मौजूदा C++ प्रोग्राम में C-स्टाइल करैक्टर स्ट्रिंग की लेंथ जैसे, नल टर्मिनेटर ऐरे पॉइंट लोकेशन को छोड़कर कैरेक्टर ऐरे नंबर्स को फाइंड करने के लिए C++ यूजर <cstring> लाइब्रेरी से strlen() फ़ंक्शन को अप्लाई कर सकते हैं.

String length example in C++.

#include <iostream>

#include <cstring>  // here we use c header file/ preprocessor directive For strlen() function

using namespace std;

int main() {

    char company[] = “Vcanhelpsu, Edtech Platform”;

    cout << “Exact Length of company string variable – ” << strlen(company) << endl;  // Result – 27

    return 0;

}

Explanation of string length program.

  • यहाँ इस एक्साम्प्ल में strlen() फ़ंक्शन नल टर्मिनेटर से पहले स्टोर सभी ऐरे के कैरेक्टर नंबर्स एलिमेंट इनफार्मेशन को इंडीकेट करता है। अंत में यह नल कैरेक्टर (‘\0’) को काउंट नहीं करता है।

String copying method in C++.

C++ प्रोग्राम में C-स्टाइल करैक्टर स्ट्रिंग ऐरे डाटा टाइप इनफार्मेशन को सोर्स से डेस्टिनेशन लोकेशन में कॉपी करने के लिए, C++ यूजर <cstring> लाइब्रेरी से strcpy() फ़ंक्शन को अप्लाई कर सकते हैं.

String copying example in C++.

#include <iostream>

#include <cstring>  // here we use c header file/ preprocessor directive For strcpy() function

using namespace std;

int main() {

    char language1[] = “Vcanhelpsu, Edtech Platform”;

    char language2[50];  // here we create the destination array size sufficient

    // here it Copy language1 string data info into language2 string data

    strcpy(language2, language1);

    cout << “Original string is – ” << language1 << endl;

    cout << “here Copied string info is – ” << language2 << endl;

    return 0;

}

Explanation of String copying program.

  • यहाँ इस एक्साम्प्ल में strcpy() फ़ंक्शन language1 के कंटेंट को language2 में करैक्टर स्ट्रिंग में कॉपी करता है. जिसमें में एक नल टर्मिनेटर को लास्ट में इंडीकेट किया गया है। इसमें आप यहाँ फिक्स करते है कि डेस्टिनेशन language2 ऐरे में कॉपी की गई स्ट्रिंग और नल टर्मिनेटर को स्टोर और रिप्रेजेंट किया गया हो।

String concatenation method in C++.

C++ प्रोग्राम में C-स्टाइल करैक्टर स्ट्रिंग ऐरे डाटा इनफार्मेशन को दो अलग अलग करैक्टर ऐरे स्ट्रिंग को कॉन्कैटनेट आपस में ऐड करने के लिए, C++ यूजर <cstring> से strcat() फ़ंक्शन को मौजूदा C++ प्रोग्राम में अप्लाई कर कर सकते हैं.

String concatenation example in C++.

#include <iostream>

#include <cstring>  // here we use c header file/ preprocessor directive For strcat() function

using namespace std;

int main() {

    char text1[100] = “Java programming, “;

    char text2[] = “Python programming”;

    // here it Concatenate text2 into text1 source location to destination location

    strcat(text1, text2);

    cout << “Final Concatenated join string is – ” << text1 << endl;

    return 0;

}

Explanation of String concatenation program.

  • यहाँ इस एक्साम्प्ल में strcat() फ़ंक्शन text2 के कंटेंट को text1 में ऐड किया जाता है। यहाँ एक फिक्स साइज ऐरे डेस्टिनेशन स्ट्रिंग (text1) में ऐड कॉन्कैटनेटेड स्ट्रिंग को मूव या ऐड करने के लिए इसमें प्रॉपर स्पेस मौजूद हो।

String comparison method in C++.

C++ प्रोग्राम में C-स्टाइल करैक्टर स्ट्रिंग में ऐरे डाटा इनफार्मेशन दो अलग अलग C-स्टाइल स्ट्रिंग डाटा इनफार्मेशन को कंम्पेअर करने के लिए, C++ यूजर <cstring> हैडर फाइल लाइब्रेरी से strcmp() फ़ंक्शन को अप्लाई कर सकते हैं.

String comparison example in C++.

#include <iostream>

#include <cstring>  // here we use c header file/ preprocessor directive For strcmp() function 

using namespace std;

int main() {

    char text1[] = “Vcanhelpsu”;

    char text2[] = “Edtech”;

    if (strcmp(text1, text2) == 0) {

        cout << “Here Both strings are Same” << endl;

    } else {

        cout << “Here Both strings are different” << endl;

    }

    return 0;

}

Explanation of String comparison program.

  • यहाँ इस एक्साम्प्ल में strcmp() फ़ंक्शन दो अलग अलग text स्ट्रिंग की तुलना लेक्सिकोग्राफ़िकली आर्डर में करता है। और आउटपुट स्टेटमेंट के रूप में यह रिटर्न करता है.
  • यदि यहाँ दोनों text1 और text2  स्ट्रिंग इक्वल हैं, तो 0 वैल्यू को रिटर्न करता है,
  • यदि यहाँ text1 लेक्सिकोग्राफिकली text2 से कम है, तो नेगेटिव वैल्यू को रिटर्न करता है,
  • यदि यहाँ text1 लेक्सिकोग्राफिकली text2 से ज़्यादा है, तो पॉज़िटिव वैल्यू को रिटर्न करता है।

Finding a character in a string method in C++.

C++ प्रोग्राम में C-स्टाइल करैक्टर स्ट्रिंग ऐरे डाटा इनफार्मेशन स्ट्रिंग में पर्टिकुलर कैरेक्टर को फाइंड करने के लिए, C++ यूजर <cstring> से strchr() फ़ंक्शन को अप्लाई कर सकते हैं.

Finding a character example in C++.

#include <iostream>

#include <cstring>  // here we use c header file/ preprocessor directive For strchr() function  

using namespace std;

int main() {

    char text[] = “Vcanhelpsu, Edtech”;

    // here it Find the first occurrence of u character in given text array string ‘u’

    char* ptr = strchr(text, ‘u’);

    if (ptr != nullptr) {

        cout << “Here ‘u’ character Found at index location – ” << (ptr – text) << endl;

    } else {

        cout << “here ‘u’ character not found in text string ” << endl;

    }

    return 0;

}

Explanation of Finding a character program.

  • यहाँ इस एक्साम्प्ल में strchr() फ़ंक्शन C-स्टाइल स्ट्रिंग में किसी कैरेक्टर में सबसे पहले आने वाले सर्च एलिमेंट को फाइंड करता है। यह मौजूदा करैक्टर ऐरे में सबसे पहले आने वाले पॉइंटर सर्च वैल्यू को इंडीकेट करता है, यहाँ यदि फाइंड टेक्स्ट कैरेक्टर नहीं मिलता है. तो इसमें आउटपुट के रूप में nullptr वैल्यू को प्रोवाइड करता है।

Detail explanation of C-style String function

C-style OperationString FunctionC-style String Function Description
Get length of stringstrlen() functionHere it Returns the length of the given string (excluding ‘\0’) null pointer value.
Copy stringstrcpy()functionHere it Copies one string into another string like source to destination location.
Concatenate stringsstrcat()functionHere it Appends one string into another string.
Compare stringsstrcmp()functionHere it Compares two strings lexicographically order one by one.
Find a characterstrchr()functionHere it Finds the first occurrence of a find character in a given text or string.
Find substringstrstr()functionHere it Finds the first occurrence of a substring character in a substring.

null terminator (‘\0’) method in C++.

C++ प्रोग्राम में नल टर्मिनेटर (‘\0’) एक स्पेशल कैरेक्टर स्ट्रिंग टर्मिनेशन पॉइंट है, नल पॉइंटर का यूज़ C-स्टाइल स्ट्रिंग के लास्ट टेक्स्ट स्ट्रिंग एलिमेंट को इंडीकेट या मार्क करने में किया जाता है। नल पॉइंटर लोकेशन स्ट्रिंग में ज़रूरी एलिमेंट है. क्योंकि C-स्टाइल टेक्स्ट स्ट्रिंग अपनी टेक्स्ट स्ट्रिंग लेंथ को स्टोर नहीं करता हैं. इस वजह से यह नल टर्मिनेटर सिग्नल प्रोवाइड करता है जिससे की यह पता चल सके कि मौजूदा स्ट्रिंग कहाँ समाप्त होती है। किसी स्ट्रिंग टेक्स्ट में नल पॉइंटर के बिना, C-स्टाइल स्ट्रिंग (जैसे strlen(), strcpy(), आदि ) में यूज़ होने वाले किसी स्ट्रिंग टेक्स्ट फ़ंक्शन को यह पता नहीं चलेगा कि स्ट्रिंग कहाँ समाप्त हो रही है. जिससे की किसी प्रोग्राम में अनडिफाइंड प्रोग्राम बिहेवियर या मेमोरी एरर जनरेट हो सकते हैं।

Leave a Reply