Last active
August 29, 2015 14:08
-
-
Save nikAizuddin/820f2c6466cfd1cd369b to your computer and use it in GitHub Desktop.
Shows how to read a string that have "space" character.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*===================================================================== | |
+-------------------------------------------------------------------+ | |
| | | |
| Example how to read "Hello World" from stdin | | |
| | | |
| The main problem with scanf() is it unable to read properly | | |
| a string that have "space" character. | | |
| | | |
| This example will show how to read a string that have "space" | | |
| character. | | |
| | | |
| However, this example uses Low-Level I/O | | |
| | | |
| For further information about _read() and _write(), please | | |
| visit the Microsoft Developer Network: | | |
| http://msdn.microsoft.com/en-us/library/wyssk1bs.aspx | | |
| http://msdn.microsoft.com/en-us/library/1570wh78.aspx | | |
| | | |
+-------------------------------------------------------------------+ | |
===================================================================*/ | |
#include <io.h> /* Used for _read(), _write() */ | |
#define STDIN 0 | |
#define STDOUT 1 | |
#define BUFFER_SIZE 1024 | |
char readbuffer[BUFFER_SIZE]; | |
int main(void) | |
{ | |
int bytes_read = 0; /* stores number of bytes read from stdin */ | |
/** Read ascii string from stdin and store into readbuffer */ | |
bytes_read = _read(STDIN, /*Read data from stdin*/ | |
readbuffer, /*Store the data to readbuffer*/ | |
BUFFER_SIZE); /*Number of bytes to read*/ | |
/** Print the ascii string stored in readbuffer */ | |
_write(STDOUT, /*Write data to stdout*/ | |
readbuffer, /*Write the data from readbuffer*/ | |
bytes_read); /*Number of bytes to write*/ | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment