任何很酷的功能,从帕斯卡在ANSI C代替readln? [英] Any cool function to replace readln from pascal in ansi c?
问题描述
该readln读取,直到行的结束(输入pressed)与空间和一切,
The readln reads until the end of line (enter pressed) with spaces and everything,
我想类似的东西,但对于ANSI C(不是C ++,需要为Linux和Windows)
I would like something like that but for ansi c (not c++ and need to be for linux and windows)
我知道我可以做一个函数读取每一个字符,直到输入pressed,但如果有任何冷却器这将是巨大= D
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
谢谢!
推荐答案
您可以使用 scanf函数
用扫描集的转换是这样的:
You can use scanf
with a scanset conversion something like this:
char buffer[256];
scanf("%255[^\n]", buffer);
另一种可能是使用与fgets
:
char buffer[256];
fgets(buffer, sizeof(buffer), stdin);
在Linux(和其他POSIX杂交系统)你应该也有一个函数命名(惊讶,意外)的readline
这是类似的,但将分配必要的空间传入的数据。
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.
这篇关于任何很酷的功能,从帕斯卡在ANSI C代替readln?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!