September 25th, 2012, 10:54 PM
Help: extracting string from file
I'm a newbie and don't have much knowledge in c and I'm stuck.
I need to extract a string saved in a file , get its length and then add extra character(like zero) as a padding till it reach some size.
I have been trying to do it like this but it is not complete, I don't know how to get it to work. can you please help me
Thanks in advance.
FILE *file = fopen( argv, "r" );
if ( file == 0 )
printf( "Could not open file\n" );
while ( ( x = fgetc( file ) ) != EOF )
printf( "%c", x );
fclose( file );
September 26th, 2012, 03:34 AM
If you want to save the string for later, you need to get an array for it
Also you need to put ecah character read from the file in there.
char data; /* enough space for a string with length up to 99 */
September 27th, 2012, 06:33 PM
Thank you very much.