📖 Samacheer Kalvi · 11th TN - English Medium · Computer Science · Page 186question

Introduction to C++ · Part 5

Chapter 3: 4 · Computer Science

argument and returns its length. The length does not include the null(\ ) character. General Form: strlen(string) #include <string.h> #include <iostream> using namespace std; int main() char source[ ] = "Computer Science"; cout<<"\n Given String is "<<source<<" its Length is "<<strlen(source); return ; Output: Given String is Computer Science its Length is Program . Chapter Page - - .

. . strcmp() The strcmp() function takes two arguments: string1 and string2. It compares the contents of string1 and string2 lexicographically.

General Form: strcpy(String1, String2) The strcmp() function returns a: • Positive value if the first differing character in string1 is greater than the corresponding character in string2. (ASCII values are compared) • Negative value if the first differing character in string1 is less than the corresponding character in string2. • if string1 and string2 are equal. #include <string.h> #include <iostream> using namespace std; int main() char string1[] = "Computer"; char string2[] = "Science"; int result; result = strcmp(string1,string2); if(result== ) cout<<"String1 : "<<string1<<" and String2 : "<<string2 <<"Are Equal"; if (result< ) cout<<"String1 :"<<string1<<" and String2 : "<<string2 <<" Are Not Equal"; Output String1 : Computer and String2 : Science Are Not Equal Program .

. . . strcat() The strcat() function takes two arguments: target and source.

This function appends copy of the character string pointed by the source to the end of string pointed by the target. Chapter Page - - General Form: strcat(Target, source) #include <string.h> #include <iostream> using namespace std; int main() char target[ ] = "Learning C++ is fun"; char source[ ] = " , easy and Very useful"; strcat(target, source); cout << target ; return ; Output Learning C++ is fun , easy and Very useful Program . . .

. strupr() The strupr() function is used to convert the given string into Uppercase letters. General Form: strcat(string) using namespace std; #include<iostream> #include<ctype.h> #include<string.h> int main() char str1[ ]; cout<<"\nType any string in Lower case :"; gets(str1); cout<<"\n Converted the Source string “<<str1<<into Upper Case is "<<strupr(str1); return ; Output: Type any string in Lower case : computer science Converted the Source string computer science into

Related topics

Have a question about this topic?

Get an AI answer grounded in your actual textbook — with the exact page reference.

Ask AI about this topic →