在C中查找字符串数组中的字符串数 [英] Find the number of strings in an array of strings in C
本文介绍了在C中查找字符串数组中的字符串数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
char* names[]={"A", "B", "C"};
有没有办法找到数组中字符串的数量?例如,在这种情况下,它应该输出:3.
Is there a way to find the number of strings in the array? For example, in this case it should output: 3.
推荐答案
在这种情况下,您可以将总大小除以第一个元素的大小:
In this case you can divide the total size by the size of the first element:
num = sizeof(names) / sizeof(names[0]);
请注意,这适用于数组.它不适用于指针.
Careful though, this works with arrays. It won't work with pointers.
这篇关于在C中查找字符串数组中的字符串数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文