在没有空格的情况下区分scanf中的字符串和int
我试图区分字符串和int,并使用scanf()将两者分开 例如:罗恩·勃艮第41 是否可以使用在没有空格的情况下区分scanf中的字符串和int,c,string,int,scanf,C,String,Int,Scanf,我试图区分字符串和int,并使用scanf()将两者分开 例如:罗恩·勃艮第41 是否可以使用scanf(“%s%s%i”、姓名、姓氏和编号) 得到 姓名=罗恩 姓氏=勃艮第 数字=41是的,很有可能。你可以这样写你的scanf- if(scanf("%19s %19[^0-9]%d",name,last_name,&number)==3){ //assuming both array of size 20 /* ^ this will read a
scanf(“%s%s%i”、姓名、姓氏和编号)
得到
姓名=罗恩
姓氏=勃艮第
数字=41是的,很有可能。你可以这样写你的
scanf
-
if(scanf("%19s %19[^0-9]%d",name,last_name,&number)==3){ //assuming both array of size 20
/* ^ this will read and store in array until a numbers is encountered */
// print them
}
@Lenny很高兴这有帮助:)