shivam LAB 6 (1)
shivam LAB 6 (1)
Introduction to string:
String is the set of characters, digits and symbol. The end of string is marked with special character, the ‘\0’ that
means Null character. The size in a character string represents the maximum number of characters that the string
can hold.
2. strrev() Function:
The strrev() function is used to reverse the given string. It takes a string, reverses it and stores in the
same string.
Syntax: strrev (str);
3. strcpy() Function:
The strcpy() function is used to copy one string into another string. It takes two strings one empty string
and one given string. It copies the given string into empty string.
Syntax: strcpy[str1,str2];
4. strcat() Function:
The strcat() function is used to join or concatenate one string into other string. It takes two string and
second string is concatenated over first string.
Syntax: strcat[str1,str2];
5. strcmp() Function:
The strcmp() function is used to compare two strings, character by character and stop comparison when
there is a difference in the ASCII value or the end of any one string and returns ASCII difference of the
characters that is integer which is either zero, negative value or positive value.
Syntax: v= strcmp[str1,str2];
6. strlwr() Function:
The strlwr() function is used to convert upper case characters of string into lower case characters.
Syntax: strlwr (str);
7. strupr() Function:
The strupr() function is used to convert lower case characters of string into upper case characters.
Syntax: strupr (str);
1. Write C Program to input any five strings and print them:
#include<stdio.h>
#include<string.h>
int main()
char strings[5][100];
printf("Enter 5 strings:\n");
scanf("%s", strings[i]);
printf("\nYou entered:\n");
printf("%s\n", strings[i]);
return 0;
OUTPUT:
2. Write C Program to find length of entered string using strlen():
#include<stdio.h>
#include<string.h>
int main() {
char str[50];
int a;
gets(str);
a=strlen(str);
OUTPUT:
3. Write C Program to read a string with space and reverse that using strrev():
#include<stdio.h>
#include<string.h>
int main()
char str[100];
gets(str);
strrev(str);
return 0;
OUTPUT:
4. Write C Program to read a string and convert that into lower case and upper case. [use strlwr() and strupr()]:
#include<stdio.h>
#include<string.h>
int main()
char str[100];
gets(str);
strlwr(str);
strupr(str);
return 0;
OUTPUT:
#include<string.h>
int main()
char str1[100],str2[100];
printf("Enter a string:");
gets(str1);
strcpy(str2,str1);
puts(str2);
return 0;
OUTPUT:
6. Input any two strings and know which has greater ASCII value.[Note: use strcmp()]:
#include<stdio.h>
#include <string.h>
int main() {
char str1[100],
str2[100]; printf("Enter
scanf("%s", str1);
printf("Enter second
str2);
else {
return 0;
}
OUTPUT:
7. Write C Program to read a string and concatenate with another string using strcat().
#include <stdio.h>
#include <string.h>
int main() {
scanf("%s", str1);
scanf("%s", str2);
strcat(str1, str2);
return 0;
OUTPUT:
#include <string.h>
int main() {
scanf("%s", str);
strcpy(rev, str);
strrev(rev);
if (strcmp(str, rev) == 0) {
} else {
return 0;
OUTPUT:
9. Write C Program to input any ten names of students and arrange them in descending/ascending order:
#include <stdio.h>
#include <string.h>
int main() {
char names[10][50], temp[50];
int i, j, order;
return 0;
}
Output:
10. Write C program to input any ten strings and search a string in that list:
#include <stdio.h>
#include <string.h>
int main() {
int i, found = 0;
printf("Enter 10 strings:\n");
scanf("%s", strings[i]);
scanf("%s", search);
if (strcmp(strings[i], search) == 0) {
found = 1;
break;
} if (found) {
} else {
return 0;
OUTPUT:
CONCLUSION:
An array of strings in C is useful for storing and managing multiple strings efficiently. Instead of
using multiple char arrays, we can store a list of strings in a single 2D char array. This makes
operations like input handling, searching, sorting, and comparison easier. It is widely used for tasks
like storing names, words, or other text-based data in applications. Arrays of strings simplify data
management and improve code readability in programs that involve handling multiple text entries.