STRING OPERATIONS
PRESENTATION BY…
[Link].
• [Link] SIAL.
DEFINITION:
*A string is a sequence of characters enclosed within double quotes.
Eg:”c programming”
*The terminating null character is not counted while determining the length of a
string.
*The empty string is written as” “.
DECLARATION AND INISIALIZATION OF STRING:
*C doesn't support as a datatype.
*So they are declared as a array of characte in the string_name.
Char string-name[30];
This statement declared a charcter array text with 30 characters.
Charname[5]=“Nisha”
* C also permits to initialise a character array without specifying the number of
elements.
READING STRINGS:
• The scanf function with %s format specification can be used
to read a string from the user and store it in a character array.
*string operations: In c there are large [Link] functions.
The functions use the standard header file (string.h).
• strcat()-concatenates two strings.
• strcmp()-compare two strings.
• strcpy()-copies one string over other string.
• strlen()-Finds length of a string.
• strrev()-Reverse the strings.
STRING CONCATENATION:,(STRCAT)
• The process of joining two strings together is called
[Link] takes 2 strings are arguments.
• The character of second string are appended at the
end of the first string.
• The first string must have enough space to accommodate
the second string.
• Syntax:
Strcat(str1,str,2);
STRING COMPARISON:(STRCPY)
• The strcpy() functions compares two strings.
If both strings are identical then this function
return 0.
• Otherwise returns a numerical value which
the difference between the 1st and 2nd character.
• Syntax:
• Strcpy(str1,str2);
COPYING A STRING:
• The strcpy() function copies the string to the destination
string.
• Syntax:
• Strcpy(str1,str2);
• Str1 is target [Link] stores the contents of the source
string in str2.
LENGTH OF A STRING:
• The strlen() function is used to find the length of a string.
• This function return the length of the string terminating null character is not counted
while determining the length of the string.
• Syntax:
• len=strlen(string);
• The process is terminated on the occurrence
null character ‘\0”,
REVERSE STRING:
• The strrev() function reverse all the character
of a string expect the terminating null character.
• Syntax:
strrev(string);
THANK YOU…..