thanks for your help… but still it doesn’t print out 300,400 on the screen. below is my fullcode: reads a file[file contain: S(300,400)] passed at commandprompt and reads the two values contained in it without printing or reading the S, the 1st bracket, the comma or the last closing bracket
#include <stdio.h>
int a;
int b;
int main ( int argc, char *argv[] )
{
if ( argc != 2 ) /* argc should be 2 for correct execution */
{
/* We print argv[0] assuming it is the program name */
printf( "usage: %s filename", argv[0] );
}
else
{
// We assume argv[1] is a filename to open
FILE *file = fopen( argv[1], "r" );
/* fopen returns 0, the NULL pointer, on failure */
if ( file == 0 )
{
printf( "Could not open file\n" );
}
else
{
/*reading file..
while (fscanf(file, "S(%d,%d)", &a, &b) == 2)
{
printf("%d,%d", a, b);
}
fclose( file );
}
}
}
You’re doing it too complicated. Just include the non-numerical parts literally:
Also, note that
printf()doesn’t support patterns, that doesn’t make a lot of sense.