
September 25th, 2012, 10:54 PM
|
|
Registered User
|
|
Join Date: Sep 2012
Posts: 2
Time spent in forums: 24 m 58 sec
Reputation Power: 0
|
|
|
Help: extracting string from file
HI
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
Code:
FILE *file = fopen( argv[1], "r" );
if ( file == 0 )
{
printf( "Could not open file\n" );
}
else
{
int x;
while ( ( x = fgetc( file ) ) != EOF )
{
printf( "%c", x );
}
fclose( file );
Thanks in advance.
Regards
|