String in C

String

Strings are actually one-dimensional array of characters terminated by a null character '\0'.

Declaration  :

char  <array_name>[size];

Example:

char name[20];

Initialization :

char greeting[] = "Hello";

OR,

  char greeting[] = {‘H', ‘e', ‘l', ‘l‘, ’o’, '\0'};

Input output String:

gets():  Input String

puts():  Output/Print String

Functions Description
strcat ( ) strcat ( str2, str1 ); – str1 is concatenated at the end of str2.
strcpy ( ) strcpy ( str1, str2) – It copies contents of str2 into str1.
strlen ( ) nt x=strlen( str1) it counts the number of characters in str1
strcmp ( ) int x=strcmp(str1,str2) : Returns 0 if str1 is same as str2. Returns <0 if strl < str2. Returns >0 if str1 > str2
strlwr ( ) strlwr(str1) Converts string to lowercase
strupr ( ) strupr(str1) Converts string to uppercase
strrev ( ) strrev(str1) Reverses the given string

Latest Current Affairs 2024 Online Exam Quiz for One day Exam Online Typing Test CCC Online Test 2024 Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Best Java Training Institute in Prayagraj (Allahabad) Best Python Training Institute in Prayagraj (Allahabad) O Level Online Test in Hindi Bank SSC Railway TET UPTET Question Bank career counselling in allahabad Sarkari Naukari Notification Best Website and Software Company in Allahabad Sarkari Exam Quiz