如何在do..while()循环中使用gets()函数? [英] How do I use gets() function inside do..while() loop?

查看:404
本文介绍了如何在do..while()循环中使用gets()函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

执行一个循环后,'gets()'函数在'do ... while'循环内无效

the 'gets()' function is not working inside a 'do ...while' loop after one cycle of execution

推荐答案

首先,不要不要使用 gets(),而是使用 getline()。请参阅 http://www.crasseux.com/books/ctutorial/gets.html [ ^ ]。



getline()的示例> http://www.crasseux.com/books/ctutorial/getline.html#getline [ ^ ]。



干杯

Andi
First of all, don't use gets(), use getline() instead. See http://www.crasseux.com/books/ctutorial/gets.html[^].

See an example of getline() at http://www.crasseux.com/books/ctutorial/getline.html#getline[^].

Cheers
Andi


add getchar();就在循环结束之前。
add getchar(); just before the loop ends.



而不是使用gets()使用fgets(),因为gets()可能导致缓冲空间超过运行。


instead of using gets() use fgets() as gets() may results in buffer space over run.


这篇关于如何在do..while()循环中使用gets()函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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