/* scanf.c Show how to write a function for input data. 1. Get a string. 2. Use C function: sscanf or just use Scanf(); **** MSC 6.0 cannot use Scanf(), because don't support function vscanf() */ #include #include char buf[100]; void main(void) { int inumber,i2; char string[80]; int no; /* method 1: use LineInput + sscanf */ Puts("Please input i,str:"); no=LineInput(buf,99); if(no){ sscanf(buf,"%d %s",&inumber,string); Print("inumber=%d string=%s",inumber,string); } else { Puts("There is not any input.\n\r"); } /* method 2: use Scanf */ /* user can try to key in 0 or 1 or 2 or 3 item, to check the return value of Scanf */ SetScanBuffer(buf,99); /* set new buffer, so after call Scanf, can get the input string */ while(1){ Puts("\n\rPlease input i,str again:(no input to quit)"); no=Scanf("%d %s%d",&inumber,string,&i2); Print("no=%d i=%d str=%s i2=%d",no,inumber,string,i2); Print("\n\rThe input string is:%s\n\r",buf); if(no==0) break; } ResetScanBuffer(); }