0% found this document useful (0 votes)
14 views9 pages

Vipin Lab Report

Uploaded by

23i358
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views9 pages

Vipin Lab Report

Uploaded by

23i358
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

EX NO:8 STRINGS

DATE:20/12/2023

AIM:

To Solve and implement the given problems using C- Strings and execute in Code blocks.

QUESTION 1:

Program to find length of a string.

SOURCE CODE:

#include<stdio.h>

#include<string.h>

void main()

char a[20];

printf("Enter the string:");

gets(a);

printf("Length of the string '%s' is %d",a,strlen(a));

OUTPUT:

KARTHIKEYAN K M
23I328
QUESTION 2:

Program to copy one string to another string


SOURCE CODE:
#include<stdio.h>
#include<string.h>
void main()
{
char a[20],copy[20];
printf("Enter the string:");
gets(a);
strcpy(copy,a);
printf("String entered: %s\n",a);
printf("Copied String : %s",copy);
}
OUTPUT:

QUESTION 3:

Program to concatenate two strings.

SOURCE CODE

#include<stdio.h>

#include<string.h>

void main()

char a[20],b[20];

printf("Enter the string 1:");

gets(a);

KARTHIKEYAN K M
23I328
printf("Enter the string 2:");

gets(b);

strcat(a,b);

printf("String after concatenation: %s",a);

OUTPUT:

QUESTION 4:

Program to compare two strings.


SOURCE CODE:

#include<stdio.h>

#include<string.h>

void main()

char a[20],b[20];

int compare;

printf("Enter the string 1:");

gets(a);

printf("Enter the string 2:");

gets(b);

compare=strcmp(a,b);

if(compare==0)

printf("The two strings are equal.");

KARTHIKEYAN K M
23I328
else

printf("The two strings are not equal.");

OUTPUT:

QUESTION 5:

Program to convert lowercase string to uppercase.

SOURCE CODE:

#include<stdio.h>

#include<string.h>

void main()

char a[20];

printf("Enter the string 1:");

gets(a);

strupr(a);

printf("String after converted: %s",a);

OUTPUT:

KARTHIKEYAN K M
23I328
QUESTION 6:

Program to convert uppercase string to lowercase.

SOURCE CODE:

#include<stdio.h>

#include<string.h>

void main()

char a[20];

printf("Enter the string 1:");

gets(a);

strlwr(a);

printf("String after converted: %s",a);

OUTPUT:

QUESTION 7:

Program to toggle case of each character of a string.

SOURCE CODE:

#include<stdio.h>

#include<string.h>

void main()

char a[20];

KARTHIKEYAN K M
23I328
printf("Enter the string :");

gets(a);

int i=0;

while(a[i]!='\0')

if(a[i]>='a'&&a[i]<='z')

a[i]=a[i]-32;

else if(a[i]>='A'&&a[i]<='Z')

a[i]=a[i]+32;

i++;

printf("String after case toggling: %s",a);

OUTPUT:

QUESTION 8:

Program to find reverse of a string.

SOURCE CODE:

#include<stdio.h>

#include<string.h>

void main()

char a[20];

printf("Enter the string :");

KARTHIKEYAN K M
23I328
gets(a);

int i=0;

strrev(a);

printf("Reverse of the string: %s",a);

OUTPUT:

QUESTION 9:

Program to check whether a string is palindrome or not.

SOURCE CODE:

#include<stdio.h>

#include<string.h>

void main()

char a[20],b[20];

printf("Enter the string :");

gets(a);

strcpy(b,a);

strrev(a);

if(strcmp(a,b))

printf("The string is not a palindrome.");

else

printf("The string is a palindrome.");

KARTHIKEYAN K M
23I328
OUTPUT:

QUESTION 10:

Program to find total number of alphabets, digits or special character in a string.

SOURCE CODE:

#include<stdio.h>

#include<string.h>

void main()

char a[20];

int countalpha=0,countspecial=0;

printf("Enter the string :");

gets(a);

int i=0;

while(a[i]!='\0')

if((a[i]>='a'&&a[i]<='z')||a[i]>='A'&&a[i]<='Z')

countalpha++;

else

countspecial++;

i++;

printf("The number of alphabets is : %d\n",countalpha);

KARTHIKEYAN K M
23I328
printf("The number of digits and special characters is : %d",countspecial);

OUTPUT:

RESULT:

All the programs using C-Strings are successfully executed.

KARTHIKEYAN K M
23I328

You might also like