本文介绍了我怎样才能从输入字符串,不包括使用与fgets一个换行符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在其他地方写输入的字符串,不知道如何与出现与此字符串,我用标准输入和与fgets收购的一部分,新的生产线做了。
I'm trying to write an inputted string elsewhere and do not know how to do away with the new line that appears as part of this string that I acquire with stdin and fgets.
char buffer[100];
memset(buffer, 0, 100);
fgets(buffer, 100, stdin);
printf("buffer is: %s\n stop",buffer);
我试图限制数据的获取与fgets以及限制多少数据被写入但新线保持量。我怎么能简单地得到所输入的字符串,最多有没有别的写的最后一个字符?
I tried to limit the amount of data that fgets gets as well as limiting how much of the data is written but the new line remains. How can I simply get the inputted string up to the last character written with nothing else?
推荐答案
尝试
fgets(buffer, 100, stdin);
size_t ln = strlen(buffer)-1;
if (buffer[ln] == '\n')
buffer[ln] = '\0';
这篇关于我怎样才能从输入字符串,不包括使用与fgets一个换行符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!