by divyab on March 15th, 2009

divyab

Question

Help answer this question below.

WHAT IS THE DIFFERENCE BETWEEN fscanf() and sscanf()

  • Like
  • Report

Answers. 2 helpful answers below.

  • by POP Fan on August 20th, 2009

    POP Fan

    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

    No comments. Post one | Permalink

  • by kitiara on March 15th, 2009

    kitiara

    f rather than s at the beginning??...

    No comments. Post one | Permalink

Want to attach an image to your answer? Click here.

Did this answer your question? If not, then ask a new question or create a poll.

More Questions. Additional questions in this category.

You're reading WHAT IS THE DIFFERENCE BETWEEN fscanf() and sscanf()

Follow us on Facebook!

Related Ads

ANSWERBAG BUZZ

Difference between scanf and sscanf
Difference between sscanf and scanf
Difference fscanf et sscanf
Difference between scanf fscanf
Difference between scanf and fscanf