1. 程式人生 > >怎麽通過scanf讀取一個空白前的字符

怎麽通過scanf讀取一個空白前的字符

pos log 姓名 輸入 printf style return sca ***

 1 /*************************************************************************
 2 > File Name: scanf2.c
 3 > Author: Mr.Yang
 4 > Purpose:scanf演示 
 5 > Created Time: 2017年05月21日 星期日 09時28分55秒
 6 ************************************************************************/
 7 
 8 #include <stdio.h>
 9
#include <stdlib.h> 10 11 int main(void) 12 { 13 char fname[20]; 14 char sname[20]; 15 16 printf("請輸入你的姓名:"); 17 scanf("%[^ ]%s",fname,sname);//%[^ ]表示讀取空白之前的字符 18 19 printf("你的姓是:%s,你的名是:%s\n",fname,sname); 20 21 return 0; 22 }

怎麽通過scanf讀取一個空白前的字符