Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我需要用C编写一个程序,它接受命令行输入,将其放入一个字符串数组,并以相反的方式打印该数组 #包括 #包括string.h int concat(char str[],char*lngstring[],int x); void printreverse(字符lngstring[],int x); #定义最大字符数100 int main(int argc,char*argv[]){ longstring[MAX_CHARS]={'\0'}; concat(*argv[],*longstring[],argc); printf(“%s”,长串); printreverse(*longstring[],argc); } int concat(char*str[],char*lngstring[],int x){ 整数计数=0; int count2=0; 虽然(count_C_Arrays_String_Command Line Arguments - Fatal编程技术网

我需要用C编写一个程序,它接受命令行输入,将其放入一个字符串数组,并以相反的方式打印该数组 #包括 #包括string.h int concat(char str[],char*lngstring[],int x); void printreverse(字符lngstring[],int x); #定义最大字符数100 int main(int argc,char*argv[]){ longstring[MAX_CHARS]={'\0'}; concat(*argv[],*longstring[],argc); printf(“%s”,长串); printreverse(*longstring[],argc); } int concat(char*str[],char*lngstring[],int x){ 整数计数=0; int count2=0; 虽然(count

我需要用C编写一个程序,它接受命令行输入,将其放入一个字符串数组,并以相反的方式打印该数组 #包括 #包括string.h int concat(char str[],char*lngstring[],int x); void printreverse(字符lngstring[],int x); #定义最大字符数100 int main(int argc,char*argv[]){ longstring[MAX_CHARS]={'\0'}; concat(*argv[],*longstring[],argc); printf(“%s”,长串); printreverse(*longstring[],argc); } int concat(char*str[],char*lngstring[],int x){ 整数计数=0; int count2=0; 虽然(count,c,arrays,string,command-line-arguments,C,Arrays,String,Command Line Arguments,好的,我给你点实际尝试的分数,不仅仅是要求我们为你写这篇文章,但我必须说你做得太多了。根据你的描述,你需要的代码可以简单得多。不过,我不想为你做这件事,所以我给你一些建议: arg已经存储在一个字符串数组中,因此您不必创建单独的字符串数组来存储它们。只需使用argv即可 您的循环逻辑太复杂,无法简单地在数组中循环。当您只需在数组中循环一次时,将for循环嵌套在while循环中是完全不必要的。向前遍历:for(int i=0;i=0;i--) 缩进代码。将问题分解为子问题(您已经识别了它们-获取

好的,我给你点实际尝试的分数,不仅仅是要求我们为你写这篇文章,但我必须说你做得太多了。根据你的描述,你需要的代码可以简单得多。不过,我不想为你做这件事,所以我给你一些建议:

  • arg已经存储在一个字符串数组中,因此您不必创建单独的字符串数组来存储它们。只需使用argv即可

  • 您的循环逻辑太复杂,无法简单地在数组中循环。当您只需在数组中循环一次时,将for循环嵌套在while循环中是完全不必要的。向前遍历:
    for(int i=0;i
    。向后遍历:
    for(int i=len-1;i>=0;i--)


缩进代码。将问题分解为子问题(您已经识别了它们-获取参数、串联、反转、打印)。并逐一解决。参数已经存在于字符串数组中。请注意,
string.h
具有
strcat
,因此您不需要编写它。如果您在web上搜索,这个常见的家庭作业问题的点击率会很高。这样,我就不需要将数组复制到新数组中了?我需要使用一个有趣的指针修改数组对吗?还要感谢您迄今为止的帮助,特别是对循环的建议。不需要修改数组。您只需向后遍历它,并在运行时打印其中的每个值。
#include <stdio.h>
#include string.h

int concat(char str[], char *lngstring[], int x);
void printreverse(char lngstring[], int x);
#define MAX_CHARS 100

int main( int argc, char *argv[] )  {
    longstring[MAX_CHARS] = {'\0'};
    concat(*argv[], *longstring[],argc);
    printf("%s", longstring);
    printreverse(*longstring[],argc);
}


int concat(char *str[], char *lngstring[], int x){
    int count = 0;
    int count2 = 0;
    while(count <= (2 * x){
        lngstring[count] = str[count2];
        count += 1;
        lngstring[count] = " ";
        count += 1;
        count2 += 1;
    }
    return 0;
}

void printreverse(char *lngstring[], int x){
    char *cas[] = lngstring;
    int count = 0;
    int count2 = x;
    char temp[];
    char temp2[];
    while(count <= x){

        for(i = 0; i < x; i++){
            char temp[] = cas[count];
            char temp2[] = cas[count2];
            cas[count2] = temp;
            cas[count] = temp2;
            count++;
            count2--;
        }
        //reverse the order of strings in array
        count = 0;
        while(count <= x){
        int bs = strlen(cas[count]);
        int zx = bs;
        char temp[] = cas[count]
        for(i = 0; i <= bs; i++){
            char temps = temp[i]
            char temps2 = temp[zx]
            temp[i] = temps2;
            temp[zx] = temps;
            zx--;
        }
        //reverse each individual string
        cas[count] = temp;
    }
    printf("%s",cas)
}