任何很酷的功能,从帕斯卡在ANSI C代替readln? [英] Any cool function to replace readln from pascal in ansi c?

查看:130
本文介绍了任何很酷的功能,从帕斯卡在ANSI C代替readln?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

该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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆