0% found this document useful (0 votes)
16 views4 pages

Assignement 8

The document contains 5 code snippets that demonstrate different string manipulation functions in C including: 1) A function to compare two strings 2) Functions to count the occurrences of different vowels in a string 3) Functions to count the occurrences of uppercase, lowercase, and special characters in a string 4) A function to change the case of all characters in a string from uppercase to lowercase and vice versa 5) A function to concatenate two strings

Uploaded by

Deep Saha
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)
16 views4 pages

Assignement 8

The document contains 5 code snippets that demonstrate different string manipulation functions in C including: 1) A function to compare two strings 2) Functions to count the occurrences of different vowels in a string 3) Functions to count the occurrences of uppercase, lowercase, and special characters in a string 4) A function to change the case of all characters in a string from uppercase to lowercase and vice versa 5) A function to concatenate two strings

Uploaded by

Deep Saha
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/ 4

//Q1

#include<stdio.h>
int sim(char A[100],char B[100]){
int i=0;
while(A[i]!='\0' && B[i]!='\0'){
if(A[i]!=B[i]){
return 0;
}
i++;
}
return 1;
}

int main(){
char A[100];
char B[100];
printf("Enter a string A: ");
fgets(A,100,stdin);
printf("enter a string B: ");
fgets(B,100,stdin);
printf("%d",sim(A,B));
return 0;
}
output
Enter a string A: dulal
enter a string B: dulal
1

//Q2
#include<stdio.h>
int vowl1(char A[100]){
int i;
int count=0;
for(i=0;A[i]!='\0';i++){
if(A[i]=='a'){
count++;
}
}
return count;
}
int vowl2(char A[100]){
int i;
int count=0;
for(i=0;A[i]!='\0';i++){
if(A[i]=='e'){
count++;
}
}
return count;
}
int vowl3(char A[100]){
int i;
int count=0;
for(i=0;A[i]!='\0';i++){
if(A[i]=='i'){
count++;
}
}
return count;
}
int vowl4(char A[100]){
int i;
int count=0;
for(i=0;A[i]!='\0';i++){
if(A[i]=='o'){
count++;
}
}
return count;
}
int vowl5(char A[100]){
int i;
int count=0;
for(i=0;A[i]!='\0';i++){
if(A[i]=='u'){
count++;
}
}
return count;
}
int main(){
char A[100];
printf("Enter a string: ");
fgets(A,100,stdin);

printf("a:%d\ne:%d\ni:%d\no:%d\nu:%d\n",vowl1(A),vowl2(A),vowl3(A),vowl4(
A),vowl5(A));
return 0;
}

output
Enter a string: dulal
a:1
e:0
i:0
o:0
u:1

//Q3

#include<stdio.h>
int uppcs( char A[100]){
int i;
int count=0;
for(i=0;A[i]!='\0';i++){
if(A[i]>=65 && A[i]<=90){
count++;
}
}
return count;
}
int lowcs( char A[100]){
int i;
int count=0;
for(i=0;A[i]!='\0';i++){
if(A[i]>=97 && A[i]<=122){
count++;
}
}
return count;
}
int spcs( char A[100]){
int i;
int count=0;
for(i=0;A[i]!='\0';i++){
if(A[i]>=33 && A[i]<=47){
count++;
}
}
return count;
}
int main(){
char A[100];
printf("enter a string: ");
fgets(A,100,stdin);

printf("uppcase:%d\nlowcase:%d\nspcase:%d\n",uppcs(A),lowcs(A),spcs(A));
return 0;
}

output
enter a string: dulal
uppcase:0
lowcase:5
spcase:0

//Q4

#include<stdio.h>
char* rud(char A[100]){
int i;
int output;
for(i=0;A[i]!='\0';i++){
if(A[i]>=65 && A[i]<=90){
A[i]+=32;
}
else if(A[i]>=97 && A[i]<=122){
A[i]-=32;
}
}
return(A);
}
int main(){
char A[100];
printf("enter string A: ");
fgets(A,100,stdin);
puts(rud(A));
return 0;

output
enter string A: dulal
DULAL

//Q5
#include<stdio.h>
void concat(char A[100],char B[100],char C[100]){
int i=0,j=0;
while(A[i]!='\0'){
C[j]=A[i];
i++;
j++;
}
i=0;
while(B[i]!='\0'){
C[j]=B[i];
i++;
j++;
}
C[j]='\0';
printf("The concatenated string:%s",C);

}
int main(){
char A[100];
char B[100];
char C[100];
printf("Enter the string A: ");
fgets(A,100,stdin);
printf("Enter the string B: ");
fgets(B,100,stdin);
concat(A,B,C);
return 0;
}
output
Enter the string A: ramesh
Enter the string B: kumar
The concatenated string:ramesh
kumar

You might also like