Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Microsoft C - <b>sscanf() read formatted data from string</b> http://www.X-Hacker.org [<<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()

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson