find the number of strings in an array of strings in C

前端 未结 9 1432
长发绾君心
长发绾君心 2020-12-13 18:00
char* names[]={\"A\", \"B\", \"C\"};

Is there a way to find the number of strings in the array. Like, for example in this case, it has to be 3. Ple

9条回答
  •  误落风尘
    2020-12-13 18:44

    Making the Array Of Strings to run in a While loop with an Increment Operator, Until the loop becomes NULL, gives the Array Size:

    #include
    char* names[]={"A", "B", "C"};
    
    int main(){
    int nameSize = 0;
    while(names[++nameSize]!='\0');
    }
    
    for(i=0;i

    Output:

    A
    B
    C
    

提交回复
热议问题