That's working great. Now all I have to do is write functions to determine the number of vowels, characters, and words, as well as one to test if it's a palindrome or not. Then, I'll be all set =D
That's working great. Now all I have to do is write functions to determine the number of vowels, characters, and words, as well as one to test if it's a palindrome or not. Then, I'll be all set =D
One last question. Should the following code work to determine the number of words in a string? I.e. I'm assuming all words are seperated by spaces.
The man page says isspace should return a zero for true. Thus, every time the function returns a 0, it indicates another word. Or, for a single-word string ( no spaces ), I simply say numWords = 1. Whenever I run it like this, it simply counts the number of letters, not white spaces. For the string "anna" it tells me there are 4 words. Any ideas?Code:for( i = 0; i < strLen; i++ ) { if ( isspace (strArray[input-1][i] == 0 ) { numWords++; } }
> char buffer[101];
> char buf[100];
Why the change in size?
Carefully crafted input files would result in more calls to fgets() in the 2nd loop than in the first loop, thus throwing off your count.
> while ( fgets ( buf, 100, data ) != NULL )
Use
while ( fgets ( buf, sizeof buf, data ) != NULL )
> rewind ( data );
This should really be in ReadNumStrings()
Similarly, main() should be in charge of calling functions
It keeps your functions focussed on one specific taskCode:FillArray ( data, strArray, numStrings ); userInput = MenuOne ( numStrings, strArray ); MenuTwo ( userInput, strArray );
> strArray[counter] = (char *) malloc (strLen * sizeof (char));
There is no need to cast malloc - this is C
Also, you're short by a char - you forgot to count the \0
strArray[counter] = malloc ( (strLen+1) * sizeof (char));
One more thing, next time you have so much source code, use ZIP and use the attach file feature. Makes it much easier for us to simply download and unzip
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
it should say isspace returns true (nonzero) for a space and 0 for a non-space.The man page says isspace should return a zero for true.
You're absolutely right, I read it wrongOriginally Posted by nonpuz