main(){ chara">
What does string to number and number to string conversion mean in C programming language?
There are two functions available for conversion. They are -
We can use the sscanf() function to convert a string to a number-
sscanf (string name, “control string”,variable list)
#includemain (){ char a[20] = “02 01 2010”; int day, mon, yr; clrscr(); sscanf (a, “%d%d %d”, &day, &mon, &yr); printf ( “Day =%d”, day); printf ( “Month = %d”, mon); printf ( “Year = %d”, yr); getch (); }
Day = 02 Month = 01 Year = 2010
We can usesprintf()function to convert string to number −
sprintf ( string name, “control string”, variable list)
#includemain (){ char a[50]; int day,mon,yr; day = 02; mon = 01; yr = 2010; crlscr(); sprintf (a, “%d/%d/%d”, day, mon, yr); printf ( “today’s date =%s”,a); getch (); }
Today’s date is 02/01/2010.
The above is the detailed content of Convert string to number and number to string using C language. For more information, please follow other related articles on the PHP Chinese website!