is there a standard function to read exactly one word from a file (a word means to me: everything between spaces or tabs or cr's or linefeeds)
stormbringer
is there a standard function to read exactly one word from a file (a word means to me: everything between spaces or tabs or cr's or linefeeds)
stormbringer
Not really
You could use
fscanf( fp, "%s", word );
But you don't really know how big the word is (it could be 1MB long for some badly formatted file)
The only safe way to do this is to use fgets to read a line, then write some code to look at that line to decide where the words are in that line.
You can write you own little function to accomplish reading one word at a time by using getc.
Put getc in a while loop and have it look for spaces, cr(s) and new lines.
Use putc to put your individual characters in an array, then decide what to do with the word that you read in.
What? Um, no. First off, putc doesn't put anything into an array. It puts it into a file (using fputc), or the standard output device. Now I suppose it is possible to redirect stdout to a file, but still, that doesn't get it into an array.Originally posted by gabulldog
Use putc to put your individual characters in an array, then decide what to do with the word that you read in.
Unless of course, you redirect standard out to a file, or perhaps another application, and then used that to read the input, or just read the file, and then put it into an array.
But really, is there really any point? Why on earth would you need a function to put some data in an array?
Quzah.Code:c = fgetc( myfile ); if( !isspace( c ) ) { array[counter++] = c; }
Hope is the first step on the road to disappointment.
You're right about putc. My bust.