ADVERTISEMENT
ADVERTISEMENT

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

ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions


ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.