Write C programme for followings:
i) Counting the number of words in a given string
i)
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
char str[1000];
int i=0;
printf(“Enter the string: “);
scanf(“%s”,str);
while(str[i]!=’\0’)
{
i++;
}
printf(“There are %d words.”i);
getchar();
getch();
}
ii) Concatenating two
given strings
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
char
a[1000],b[1000];
int
i=0,j=0,k;
printf(“Enter
the string: “);
scanf(“%s”,a);
printf(“Enter
the string: “);
scanf(“%s”,b);
while(a[i]!=’\0’)
{
i++;
}
while(b[j]!=’\0’)
{
j++;
}
for(k=0;k<j;k++)
{
a[i+k]=b[k];
}
printf(“%s”,a);
getchar();
getch();
}
No comments:
Post a Comment