Register | Sing In

New posts

Stacks in C programming Linked Lists in C programming File Input/Output in C programming Check prime numbers in C Programming C Programming Enumeration C Programming Union

Archives

2013-10 2013-09 2013-08

Function sscanf in C programming

September 10, 2013 Posted by: GPA Views: 1088 0 comments

Problem

Write simple program in C using function sscanf.

Solution

In this article, you will know how to read formatted data from character array str. You need include header file <stdio.h> for this program.

Declaration:

int sscanf( char *str, const char *format, ... );

The function uses the same specifiers as scanf %d for integer, %lf" for double and so on. About specifiers you can read here Standard Library function scanf.

Example:



#include <stdio.h>
#include <stdlib.h>
//main function
int main(int argc, char *argv[])
{
   char strofintegeranddouble[]="152 5985.55"; //create char array
   int firstNumber;//declare variable for first Number
   double secondNumber;//declare variable for second Number
   printf("globalproganswer.com\n");
   printf("The values stored in character array are: %s",strofintegeranddouble);//show string strofintegeranddouble
   //call function sscanf parce char array strofintegeranddouble
   sscanf(strofintegeranddouble, "%d%lf", &firstNumber, &secondNumber);//read first number from char array  strofintegeranddouble
   //show result
   printf( "\nInteger value is : %d \nDouble value is: %0.2f\n\n", firstNumber,secondNumber );
   system("PAUSE");//delay
   return 0;
}

Output

Function sscanf

Download this example

0 Comments...

Leave a Reply

Please, Sing In to leave a Reply for this material.



Online Chat

LiveZilla Live Help

Popular posts

Function strtok in C programming Check prime numbers in C Programming C Programming Union Linked Lists in C programming File Input/Output in C programming C Programming Enumeration

RSS-subscribe

New materials

Subscribe