/* SCANF.c: 1. Show how to write a function for input data. 2. To get a string. 3. To use C function: sscanf,or just use Scanf(). ** MSC 6.0 cannot use Scanf(), because don't support function vsscanf() Compiler: BC++ 3.1, Turbo C ++ 1.01(3.01) (free from http://community.borland.com/museum) Compile mode: large Project: Scanf.C ..\..\Lib\(8000E.Lib,7188XAL.Lib,7188XBL.Lib,7188XCL.Lib or 7188EL.Lib) Hordware: 7188/8000 Note: Before the program call InstallCom1( ), it can use Kbhit( ), Getch( ), Putch( ),Print( ), Scanf( )... to send/receive data to/from COM1 of 7188x/8000. But after call Installcom1( ) these functions will not work until the program call RestoreCom1( ). All these I/O functions only apply to the main Command port (console port) Command port list 7188 COM4 7188XA COM4 7188XB COM1 7188XC COM1 7188EN COM1 8000 COM1 [07/Dec/2006] by Liam [13/July/2011] by Nicholas */ #include #include #include #include #include #include "..\..\lib\7188e.h" char buf[100]; void main(void) { int inumber,i2; char string[80]; int inputData; InitLib(); /* method 1: use LineInput + sscanf */ Puts("Please input integer(-32768 ~ +32767), string:"); inumber=LineInput(string, 99); if(inumber) { 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, 1, 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 integer(-32768 ~ +32767),string, integer again(input null space to quit):"); inputData=Scanf("%d %s %d", &inumber, string, &i2); if( buf[0]>='0' && buf[0]<='9' ) { if(inputData == 1) { Print("inputData=%d integer =%d", inputData, inumber); Print("\n\rThe input string is:%s\n\r", buf); } else if(inputData == 2) { Print("inputData=%d integer=%d string=%s ", inputData, inumber, string); Print("\n\rThe input string is:%s\n\r", buf); } else if(inputData == 3) { Print("inputData=%d integer1=%d string=%s integer2=%d", inputData, inumber, string, i2); Print("\n\rThe input string is:%s\n\r", buf); } } else if(buf[0]==' ') { break; } else { Print("The first input is not an integer.\n\r"); } } ResetScanBuffer(); }