String Handling in C Programming

String :
A string is a collection of characters. Strings are always enlosed in double quotes as “string_constant”.

Strings are used in string handling operations such as,

•	Counting the length of a string.
•	Comparing two strings.
•	Copying one string to another.
•	Converting lower case string to upper case.
•	Converting upper case string to lower case.
•	Joining two strings.
•	Reversing string.

String Declaration in C:
The string can be declared as follow :

Syntax:

	char string_nm[size];

Example:

	char name[50];

C String Structure :
When compiler assigns string to character array then it automatically supplies null character (‘\0’) at the end of string. Thus, size of string = original length of string + 1.

	char name[7];
	name = "TECHNO"

Read Strings in C:
To read a string, we can use scanf() function with format specifier %s.

	char name[50];
	scanf("%s",name);

The above format allows to accept only string which does not have any blank space, tab, new line, form feed, carriage return.

Write Strings in C:
To write a string, we can use printf() function with format specifier %s.

	char name[50];
	scanf("%s",name);
	printf("%s",name);

Leave A Comment

Your email address will not be published. Required fields are marked *