sscanf in c code example
Example 1: sacnf in c
/* scanf example */
#include
int main ()
{
char str [80];
int i;
printf ("Enter your family name: ");
scanf ("%79s",str);
printf ("Enter your age: ");
scanf ("%d",&i);
printf ("Mr. %s , %d years old.\n",str,i);
printf ("Enter a hexadecimal number: ");
scanf ("%x",&i);
printf ("You have entered %#x (%d).\n",i,i);
return 0;
}
Example 2: ltoa in c
ltoa() function in C language converts long data type to string data type.
Syntax for ltoa() function is given below.
------------------------------------------------------
char *ltoa(long N, char *str, int base);
Example 3: fputs in c
#include
int main () {
FILE *fp;
fp = fopen("file.txt", "w+");
fputs("This is c programming.", fp);
fputs("This is a system programming language.", fp);
fclose(fp);
return(0);
}
Example 4: sscanf in c
#include
#include
#include
int main () {
int day, year;
char weekday[20], month[20], dtm[100];
strcpy( dtm, "Saturday March 25 1989" );
sscanf( dtm, "%s %s %d %d", weekday, month, &day, &year );
printf("%s %d, %d = %s\n", month, day, year, weekday );
return(0);
}
Example 5: sscanf in c
March 25, 1989 = Saturday