The string is a sequence of characters terminated with a null character \0. The string.h header defines one variable type, one macro, and various functions for manipulating arrays of characters. Strings are always enclosed by double quotes. Whereas, character is enclosed by single quotes in C.
Example :
char x [ ] = " String " ;
or
char x [ 10 ] = { ' R ' , ' A ' , ' M ' , ' \0 ' } ;
or
char x [ 10 ] = " Tutor joes " ;
Difference between above declarations are, when we declare char as char x [ 10 ], 10 bytes of memory space is allocated for holding the string value. #inclued<String.h> header file supports all the string functions in C. All the string functions are given below.
#include<stdio.h> #include<string.h> int main() { char c[20],a[20]; char x[10]={'R','A','M','\0'}; char y[10]={'K','U','M','A','R','\0'}; printf("x : %s",x); printf("\nEnter The String : "); gets(c); printf("\nCompare : %d ",strcmp(x,c));//String Compare printf("\nLength : %d ",strlen(c));//String Length printf("\nReverse : %s ",strrev(c));//String Reverse printf("\nUppercase : %s ",strupr(c));//String Upper printf("\nLowercase : %s ",strlwr(c));//String Lower printf("\nCopy : %s ",strcpy(a,c));//String Copy strcat(x,y); printf("\nConcatenation : %s ",x);//String Concatenation return 0; } /* char c[10]; printf("Enter The String : "); //scanf("%s",c); gets(c); printf("%s",c); */To download raw file Click Here
x : RAM Enter The String : sam Compare : -1 Length : 3 Reverse : mas Uppercase : MAS Lowercase : mas Copy : mas Concatenation : RAMKUMAR
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions