C - Get Integer and Character Values from a String using sscanf.
IncludeHelp
03 August 2016
In this code snippet, we will learn how to get Integer and String values from a formatted string using sscanf().
C Code Snippet - Get Integer and String Values from String using sscanf()
//C - Get Integer and Character Values from a String using sscanf.
#include <stdio.h>
int main(){
char *strFormat="Mike 27";
char *name;
int age;
sscanf(strFormat,"%4c%d",name,&age);
printf("Name: %s\n",name);
printf("Age: %d\n",age);
return 0;
}
Name: Mike
Age: 27