0% found this document useful (0 votes)
20 views

.//WAP To Calculate The Number of Character in A String

The document contains C code for several string manipulation programs: 1) A program to count the number of characters in a string. 2) A program to count the number of characters and whitespace in a string. 3) A program to copy one string to another string. 4) A program to concatenate two strings together. 5) A program to convert a string to uppercase. 6) A program to compare two strings for equality. 7) A program to reverse a string.

Uploaded by

Rupinder Singh
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views

.//WAP To Calculate The Number of Character in A String

The document contains C code for several string manipulation programs: 1) A program to count the number of characters in a string. 2) A program to count the number of characters and whitespace in a string. 3) A program to copy one string to another string. 4) A program to concatenate two strings together. 5) A program to convert a string to uppercase. 6) A program to compare two strings for equality. 7) A program to reverse a string.

Uploaded by

Rupinder Singh
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

27.//WAP to calculate the number of character in a string.

#include<stdio.h>

#include<stdio.h>

void main()

{ int i,count;

char a[20];

clrscr();

i=0;

count=0;

printf("Enter the string: ");

gets(a);

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

{ count++;

i++;

printf("The number is %d",count);

getch();

}
28.//WAP to find number of characters and white
spaces in a string.
#include<stdio.h>

#include<stdio.h>

void main()

{ int i,count,c;

char a[20];

clrscr();

i=0;

count=0;

c=0;

printf("Enter the string: ");

gets(a);

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

{ count++;

i++;

if(a[i]==' ')

c++;

}
printf("The number is %d",count);

printf("\nTHE number of spaces are %d",c);

getch();
}
29.//WAP to copy a string to another string.
#include<stdio.h>

#include<conio.h>

void main()

{ int i=0;

char a[20],b[30];

clrscr();

printf("Enter the string: ");

gets(a);

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

b[i]=a[i];

i++;

}b[i]='\0';

printf("The copied string is: ");

puts(b);

getch();

}
30.//WAP to concatenate.
#include<stdio.h>

#include<conio.h>

void main()

{ int i=0,j;

char a[20],b[30],c[55];

clrscr();

printf("Enter the string1: ");

gets(a);

printf("Enter the string2: ");

gets(b);

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

c[i]=a[i];

i++;

c[i]=' ';

for(j=0;b[j]!='\0';j++)

c[j+i+1]=b[j];

c[j+i+1]='\0';

printf("\nThe concatenated sting is: ") ;


puts(c);

getch();

}
31.//WAP to convert lower to upper case.
#include<stdio.h>

#include<stdio.h>

void main()

{ int i,count,c;

char string[20];

clrscr();

c=0;

printf("Enter the string: ");

gets(string);

while(string[c]!='\0')

{ if(string[c]>='a'&&string[c]<='z')

{ string[c]=string[c]-32;

c++;

printf("Entered string in upper case is %s",string);

getch();

}
32.//WAP to compare two strings.
#include<stdio.h>

#include<stdio.h>

void main()

{ int i,count,c,flag;

char a[20],b[20];

clrscr();

c=0;

printf("Enter the string1: ");

gets(a);

printf("Enter the string2: ");

gets(b);

while(a[c]==b[c])

{ if(a[c]=='\0'||b[c]=='\0')

break;

c++;

if(a[c]=='\0'&&b[c]=='\0')

flag=0;

else flag=1;

if(flag==0)

printf("Entered strings are equal");

else
printf("Entered strings are not equal");

getch();

}
33.//WAP to Reverse a String...

#include<stdio.h>
#include<conio.h>
void main()
{
char str[20],rev[20];
int i=0,j=0;
printf("Enter Any String:- ");
scanf("%s",str);
while(str[i]!='\0')
{
i++;
}
i--;
while(i>=0)
{
rev[j]=str[i];
j++;
i--;
}
rev[j]='\0';
printf("Reverse Of Your String Is:- %s",rev);
getch();
}

You might also like