please forgive me - this is only my second day writing C.
I am writing a basic app that counts how many words are in a sentance.
Here's the code.
/* Program to Determine how many words are in a string */
#include <stdio.h>
#incluse <string.h>
char input_string[200];
int word_count;
/* This function will take a string and calculate how many words are in it. ***
** It will do this by finding out how many spaces are in the string ***
*/
int words(char sentence[200])
{
int string_length, counter, count_spaces, word_amount;
string_length = strlen(sentence);
count_spaces = 0;
/*Now we loop until end of string length and calculate spaces*/
for (counter; counter == string_length; ++counter) { /*#### Compiler error here ***/
if (sentence[counter] == ' ''){
count_spaces = count_spaces + 1);
}
word_amount = count_spaces - 1;
return(word_amount);
}
int main ()
{
/* Gets sentence from user */
printf("Enter in a Sentence: ");
fgets(input_string, sizeof(input_string), stdin);
/* sends info to function 'words' to be processed - info will be sent back in integer */
word_count = words(input_string);
printf("There are %d words in this sentence\n", word_count);
return(0);
}
Here's the exact error that gcc gives me:
words.c:24: unterminated character constant
Any help would be great... thx.
(FYI - Im compiling under linux)