2021年3月20日星期六

C Function to retrieve argv contents to string

I'm not going to have the time to submit my solution any way, yet I'm so frustrated.

I am coding a function that would take argv on execution and concat its contents in a string with commands separated by \n Something like this "./a.out \n a \n b \n c \n ..etc".

Here's m code ( and it doesn't work):

#include <stdlib.h>  #include <stdio.h>  #include <string.h>  char *my_concat_params(int argc, char **argv){      char argss[argc];            for (int i = 0; i<argc;i++){          strcpy(argss[i], argv[i]);      }          return argss[0];      }      int main(int argc, char **argv){      //char *cmdlne = my_concat_params(argc , argv);      printf("%d, %s\n", argc, argv[argc-1]);      return 0;  }    

What's the proper way to navigate through the pointing to pinter and getting back a string of what i want?

https://stackoverflow.com/questions/66726401/c-function-to-retrieve-argv-contents-to-string March 21, 2021 at 04:56AM

没有评论:

发表评论