On Thu, 25 Sep 2008 11:51:59 +0100, Ben Bacarisse wrote:
Did you remove it and make the correct adjustments elsewhere? Without
code we can't know what is happening.
okay, here is the code which runs fine. DO you see any hidden bugs ?
/* A program that will ask the user for input and then will sort the input alphabetically
and will print it on stdout
* As of now it does not sort any words but it will very soon. I am writing it in parts
* when parts work fine,then we put them in one place
* Since I did not want to put any limitation on input size in this program, I have used
* dynamic memory allocation to solve the problem. My intent in creating and then solving
* this problem was purely of C learning (as defined by ANSI standard) and nothign else. I
* wanted to learn C and hence this problem and quite heavy discussion of it on comp.lang.c.
* I owe many thanks to the brillant help I got in comp.lang.c
*
* VERSION 1.0
*
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
enum { WORD_SIZE = 3 };
enum { GSW_OK, GSW_ENOMEM, GSW_ENORESIZE } ;
void print_input( char** );
size_t get_input( char** );
int get_single_word( char** );
int main( void )
{
char* pword;
size_t words_count;
words_count = get_input( &pword );
printf("words_count = %u\n", words_count);
return 0;
}
void print_words( char **ppc )
{
printf("---------------------------------------\n\n");
while( **ppc )
{
printf("%c\n", **ppc++);
}
}
size_t get_input( char** pword )
{
size_t w_cnt;
w_cnt = 0;
while( (GSW_OK == get_single_word(pword)) && ( **pword != 0) )
{
printf("You entered: [%s]\n", *pword);
++w_cnt;
free( *pword );
}
return w_cnt;
}