c语言中将字符串转化为其他类型数据 //sscanf()
在#include<stdio.h>中存在sscanf函数能将字符串中分成多个部分,分别转化为不同类型进行返回;
sscanf(char *s,type,destination)
//s为字符数组名,type为转化的种类(与scanf中的格式相同),destination为返回的目标
instance (eg):
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
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);
}