使用strlen查找用户输入的长度c [英] using strlen to find length of user input c
本文介绍了使用strlen查找用户输入的长度c的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试创建一个存储用户输入的数组,我需要将该数组设置为用户输入的确切长度.我想取用户输入的长度,并将其用作数组的长度.我如何用strlen做到这一点?有什么更好的方法吗?
I am trying to create an array that to store a user's input, and I need the array to be the exact length of the user's input. I would like to take the length of the user's input, and use this as the length of the array. How can I do this with strlen? Is there any better way?
推荐答案
在编写自己的函数之前,可以尝试以下代码:
Before writing your own function, you can try the following code:
char *str;
scanf("%ms", &str); // <--- Note the & before str
// Do something with str...
free(str);
这是对ISO C标准的扩展受所有POSIX.1-2008支持-符合标准的系统.
This is an extension to ISO C standard supported on all POSIX.1-2008-conforming systems.
这篇关于使用strlen查找用户输入的长度c的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文