c - 使用空字符值的 calloc 字符数组的长度?

标签 c arrays count null calloc

我有一个指向已调用字符数组的指针的二维数组。假设 calloc 0 输出一个字符数组,是否可以计算数组中有多少个字符,类似于:

while( next character != '\0' ){
    count++;
} return count;

更具体地说:

letters[j] = calloc(26, sizeof(char));
        scanf("%s", letters[j]);

这是我调用 char 数组的代码,然后将其设置为不超过 26 个字符的特定字符串,但可以更少。

最佳答案

int lengthOfString(char* string){
    int count = 0;
    while(string[count] != '\0'){
        count++;
    }
    return count;
}

是的,这非常有效!

关于c - 使用空字符值的 calloc 字符数组的长度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42429329/

相关文章:

c - Makefile 找不到 c 中的函数

C 用户输入不起作用(c、lua)

javascript - 使用数组 javascript 查找最长的字谜

c# - 介于另一列的值之间

mysql - 在 mySQL 中对多个相同的表求和

c - 将每个成员初始化为一个空的 C 字符串

c - 汇编语言棘手的内存地址

php - "Notice: Undefined variable"、 "Notice: Undefined index"、 "Warning: Undefined array key"和 "Notice: Undefined offset"使用 PHP

arrays - JDK 中是否有数组的 .java 源文件?

postgresql - 每行的 st_intersect 计数结果