Any cool function to replace readln from pascal in ansi c?
The readln reads until the end of line (enter pressed) with spaces开发者_开发知识库 and everything,
I would like something like that but for ansi c (not c++ and need to be for linux and windows)
I know that I can make a function that reads every char until the enter pressed but If there is anything cooler it would be great =D
Thanks!
From here there is fgets that does this.
Yes.
char * fgets ( char * str, int num, FILE * stream );
You can use scanf
with a scanset conversion something like this:
char buffer[256];
scanf("%255[^\n]", buffer);
another possibility is to use fgets
:
char buffer[256];
fgets(buffer, sizeof(buffer), stdin);
On Linux (and other POSIX-ish systems) you should probably also have a function named (surprise, surprise) readline
that's similar, but will allocate the space necessary for the incoming data.
Use fscanf function.
Are you looking for something like this.
精彩评论