[<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
sscanf()                 Read Formatted Data from String

 #include   <stdio.h>

 int        sscanf(buffer,format-string[[,argument...]]);
 char       *buffer;                     Stored data
 char       *format-string;              Format control string

    sscanf() reads data from 'buffer' into the locations given by
    'arguments'.  sscanf() operates identically to scanf(), with the
    single exception that scanf() reads data from stdin, while sscanf()
    reads data from 'buffer'.  The format-string, arguments, and return
    value of sscanf() are the same as those of scanf(); see the scanf()
    function for a complete description.

  -------------------------------- Example ---------------------------------

    This example scans 'buffer' for the given fields, which are then
    printed.

          #include <stdio.h>

          char *buffer = "001Smith,J 002Jones,B";
          int num, numread, num2;
          char name[15], name2[15];

          main()
          {
               numread = sscanf(buffer,"%3d %15s %3d %15s",
                                &num,name,&num2,name2);
               printf("number of fields read: %d \n",numread);
               printf("employee: %s (%d)\n",name,num);
               printf("employee: %s (%d)\n",name2,num2);

           }

See Also: scanf() fscanf() sprintf()
This page created by ng2html v1.05, the Norton guide to HTML conversion utility. Written by Dave Pearson