PRACTICAL-SET-5
1. Write a program to count total words in text.
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char s1[50];
int i, count = 0;
clrscr();
printf("Enter the string:");
scanf("%[^\n]s", s1);
for (i = 0;s1[i] != '\0';i++)
{
if (s1[i] == ' ')
count++;
}
printf("Total words in entered string are: %d\n", count + 1);
getch();
}
OUTPUT:
1. Write a program to count total words in text.
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char s1[50];
int i, count = 0;
clrscr();
printf("Enter the string:");
scanf("%[^\n]s", s1);
for (i = 0;s1[i] != '\0';i++)
{
if (s1[i] == ' ')
count++;
}
printf("Total words in entered string are: %d\n", count + 1);
getch();
}
OUTPUT:
string length |
No comments:
Post a Comment