How to find the length of argv[] in C

后端 未结 8 2075
青春惊慌失措
青春惊慌失措 2020-12-15 06:41
#include 
#include 
#include 

int main(int argc, char *argv[]){
    int fir; //badly named loop variable
    char *in         


        
8条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-15 06:51

    argv is an array of char, strlen only takes strings. If you want to get the length of each argument in argv (which is what I was trying to do), you must iterate through it, accessing the elements like so argv[i][j]. Using the argument argv[i][j] != '\0'. If you just want the number of arguments use argc.

提交回复
热议问题