C Strings

String operations (string.h)

C language recognizes that string is a different class of array by letting us input and output the array as a unit and are terminated by null character.
C library supports a large number of string handling functions that can be used to array out many o f the string manipulations such as:
  • Length (number of characters in the string).
  • Concatenation (adding two are more strings)
  • Comparing two strings.
  • Substring (Extract substring from a given string)
  • Copy (copies one string over another)

To do all the operations described here it is essential to include string.h library header file in the program.

strlen() function

/*write a c program to find the length of the string using strlen() function*/ 
#include 'stdio.h' 
#include ' string.h ' 
void main() 
{ 
    char name[100]; 
	int length; 
	printf(“Enter the string”); 
	gets(name); 
	length=strlen(name); 
	printf(“\nNumber of characters in the string is=%d”,length); 
} 
        


strlen() function

This function counts and returns the number of characters in a string. The length does not include a null character.
Syntax n=strlen(string);

Where n is integer variable. Which receives the value of length of the string.
Example: 
		      length=strlen(“Hollywood”); 
The function will assign number of characters 9 in the string to a integer variable length.

 

Make Comments..!!


Oops!! No posts from user.

Download Android App