How to find the length of argv[] in C

后端 未结 8 2071
青春惊慌失措
青春惊慌失措 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 07:09
    //Task = get length of argv
        string text=*argv; //assigning charValue to string variable "text"
        int l=text.length(); //getting the length of the string & assigning to variale "l"
    
        //this loop just outputs result on the screen
        for (int i=0; i<l; i++) { 
            cout << *(*argv+i) << flush;
        }
    
    0 讨论(0)
  • 2020-12-15 07:13

    Not sure why no one has suggested changing strlen to refer to a specific entry in the array of pointers to char?

     strlen(argv[0])     // also, 1, 2, up to (argc - 1)
    

    Also, http://www.cdecl.org/ helps in confirming that the char *argv[] statement is: declare argv as array of pointer to char

    0 讨论(0)
提交回复
热议问题