<<mod note: split from 2 year old thread>>
Code:
#include<stdio.h>
#include<conio.h>
#include<string.h>
main()
{
clrscr();
char *str,a[]=".!?";
int index,cnt,sntcnt=0,slen=0;
printf("Enter string: ");
gets(str);
slen=strlen(str);
for (index=0;index<slen;index++)
{
for (cnt=0;cnt<4;cnt++)
{
if (str[index]==a[cnt]||str[index]=='\0')
{
sntcnt;
}
}
}
printf("Number of sentence in the string: %d",sntcnt);
getch();
return 0;
}
#include<stdio.h>
#include<conio.h>
#include<string.h>
main()
{
clrscr();
char *str;
int index,slen=0,wrdcnt=0;
printf("Enter string: ");
gets(str);
slen=strlen(str);
for (index=0;index<=slen;index++)
{
if (str[index]==' '||str[index]==','||str[index]=='.'||str[index]=='!'||str[index]=='?'||str[index]=='\0')
{
wrdcnt++;
if (str[index]==' ')
{
wrdcnt--;
}
else
{
wrdcnt++;
}
}
}
printf("The number of words in the string is: %d",wrdcnt);
getch();
return 0;
}
yea these are the codes i have..it works kinda ok but it just counts as the condition applies...im having trouble trying to figure out the problem with this...can provide some help pls..im really new to this...