//To count the number of words in a string
#include<stdio.h>
#include<conio.h>
char words(char);
void main()
{
char string[100];
clrscr();
printf("Enter the string to reverse");
gets(string);
words(string);
getch();
}
char words(char string[] )
{
int count=0;
int i;
for(i=0;i<string[i]!='\0'; i++)
{
if(string[i]==' '&& string[i+1]!=' ')
count++;
}
printf("The number of words in a sentence is %d" , count+1);
}
// to reverse a given string
#include<stdio.h>
#include<conio.h>
char reverse(char);
void main()
{
char str1[100];
printf("Enter a string\n ");
gets(str1);
reverse(str1);
getch();
}
char reverse (char str1[])
{
int i=0, len=0;
while(str1[i]!='\0')
{
len++;
i++;
}
printf("\n The string in reverse is\n");
for(i=len-1; i>=0; i--)
{
printf("%c", str1[i]);
}
}