- NEW!
Help answer this question below.
scanf() reads values specified as arguments from stdin, whereas sscanf reads them from an array specified in the first argument. fscanf reads from the FILE pointer entered as argument 1.
For example:
int a;
scanf("%d", &a);
would store an integer value received from stdin (which is usually the keyboard) at the address of variable a.
int a;
int b[10];
register int c;
for(c=0; c<10; c++)
b[c] = c;
sscanf(b, "%d", &a);
would do the same thing but would read the values from the array b instead of stdin. A would then equal: 0123456789.
FILE *fname;
int a;
if((fname=fopen("temp.txt", "r"))==NULL)
{
printf("nFile read error.");
exit(1);
}
fscanf(fname, "%d", &a);
would be the same as the above examples, except the value would be read from the file temp.txt.
scanf is used for input from the keyboard (mostly)
sscanf is used for input from an array
fscanf is used for input from a file
f rather than s at the beginning??...
Who invented computer programming?
by Answerbag Staff on February 1st, 2011
| 1 person likes this
How do i use visual basic 2008 express?
by Answerbag Staff on August 21st, 2010
| 1 person likes this
How do I create a table in Microsoft SQL?
by Answerbag Staff on November 8th, 2010
| 1 person likes this
You make the programs for money? Lots of money?
by Mister_Bromide on January 9th, 2012
| 1 person likes this
Why do people insert QR code of the URL to be scanned in their advertisements?
by Trust.Me.I.Know on January 3rd, 2012
| 1 person likes this
You're reading WHAT IS THE DIFFERENCE BETWEEN fscanf() and sscanf()
Comments