scanf up to tab?
-
Hi! Is it possible using scanf to read a string from STDIN up to a tab character? I.e. the tab character must be regarded as %s terminator somehow. What must the format string look like? Thanks in advance and best regards, Dominik
_outp(0x64, 0xAD);
and__asm mov al, 0xAD __asm out 0x64, al
do the same... but what do they do?? ;) (doesn't work on NT) -
Hi! Is it possible using scanf to read a string from STDIN up to a tab character? I.e. the tab character must be regarded as %s terminator somehow. What must the format string look like? Thanks in advance and best regards, Dominik
_outp(0x64, 0xAD);
and__asm mov al, 0xAD __asm out 0x64, al
do the same... but what do they do?? ;) (doesn't work on NT) -
scanf() is a dangerous function because it is easy to have a buffer overflow. Try using fgets() and sscanf() instead. Both use buffers of specified size.
-
scanf() is a dangerous function because it is easy to have a buffer overflow. Try using fgets() and sscanf() instead. Both use buffers of specified size.
-
You can limit the no of characters to extract with scanf. char s[BUFFERSIZE+1]; scanf(" %*[^\t]", BUFFERSIZE, s);
Bhaskar wrote: You can limit the no of characters to extract with scanf. char s[BUFFERSIZE+1]; scanf(" %*[^\t]", BUFFERSIZE, s); It is true that you can specify the maximum width of characters assigned to a string. However, this is hard to read, and prone to error. Format strings are inherently hard to use (but extremely powerful). I just re-read the help section in MSVC++, "Format Specification Fields: scanf and wscanf Functions" and I don't believe your example is valid. For one thing, it is missing a type specifier ('s'). This is such an easy mistake (which I have done myself) that it only shows the danger in using scanf(). And even if this turns out to be a valid format string, it is almost unreadable.