#include<stdio.h>
#include<string.h>
int count(char string[]);
void main(){
int i;
char string[1001];
printf("String: \n");
gets(string);
i = words(string);
printf("No. of Words %d", i);
}
int count(char string[])
{
int i, j, k;
for(i = 0; i < strlen(string); i++){
if(string[i] == ' ')
k += 1;
else
j += 1;
}
return j;
}
I have spent a few hours searching for something that would help me count words (not letters) in a string the user types. There can be more than one space between each word. I have seen instances of using inbuilt function but I cant use them for this assignment.
Any help would be appreciated, thanks in advance.