String Function in C

String

Posted on Updated on

What is String & how to use it:

The string in C programming language is actually a one-dimensional array of characters which is terminated by a null character ”. Thus a null-terminated string contains the characters that comprise the string followed by a null.

The following declaration and initialization create a string consisting of the word “Hello”. To hold the null character at the end of the array, the size of the character array containing the string is one more than the number of characters in the word “Hello.”

char greeting[6] = {‘H’, ‘e’, ‘l’, ‘l’, ‘o’, ”};

If you follow the rule of array initialization then you can write the above statement as follows:

char greeting[] = “Hello”;

STRING COPY:

strcpy(s1, s2); Copies string s2 into string s1.

clip_image002

OUTPUT:

clip_image004

STRING CAT:

strcat(s1, s2); Concatenates string s2 onto the end of string s1.

clip_image006

OUTPUT:

clip_image008

STRING COMPARE:

Compares two string

clip_image010

OUTPUT:

clip_image012

STRING LENGTH:

strlen(s1); Returns the length of string s1.

clip_image014

OUTPUT:

clip_image016

STRING LOWER:

Converts string to lowercase

clip_image018

OUTPUT:

clip_image020

STRING UPPER:

Converts string to uppercase

OUTPUT:

clip_image024

Posted By-: Vissicomp Technology Pvt. Ltd.

Website -: http://www.vissicomp.com

Advertisements