String

String

  • A string is stored internally as an array of characters. So string is a group of character of any length.
  • A string is enclosed within double quotation marks is known as a literal. for e.g. “HELLO”

String declaration and initialization:

char item[9];

where item is name of one dimensional character array having maximum 9 character, 8 for the alphabets and one for the null character.

 

Program to read and write your name using scanf.

#include<stdio.h>
#include<conio.h>
void main(){
char name[20];
clrscr();
printf(“\n Enter your name”);
scanf(“%s”,name);
printf(“\n Hello %s”,name);
getch();
}

output:

enter your name devilson

hello devilson

String function                            use
Strlen

Strcat

Strcpy

Strcmp

Strrev

Strupr

Strlwr

Finds the length of string

Appends one string at the end of another string

Copies one string to another

Compare two strings

Reverse the string

Converts string into uppercase

Converts string into lowecase