我需要转换命令行中给出的参数,例如: $ myprogram hello world
并且单词需要用大写字母打印。除了访问双指针数组以使用 toupper() 进行更改之外,我可以做任何事情
static char **duplicateArgs(int argc, char **argv)
{
char **copy = malloc(argc * sizeof (*argv));
if(copy == NULL){
perror("malloc returned NULL");
exit(1);
}
int i;
for(i = 0; i<argc; i++){
copy[i] = argv[i];
}
char **temp;
temp = ©[1];
*temp = toupper(copy[1]);
return copy;
}