[英]distinguishing between a string and an int in scanf when there is no space
我正在嘗試區分字符串和int,並使用scanf()分隔兩者。
例如:Ron Burgundy41
是否可以使用scanf("%s %s %i", name, last_name, &number)
得到
name = Ron
last_name =勃艮第
數= 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
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.