C 值同步无法正常工作

C 值同步无法正常工作,c,arrays,loops,matrix,strcmp,C,Arrays,Loops,Matrix,Strcmp,我的程序链接中有完整的代码;请阅读,我这里的代码足够长,但不是全部: 作为评估的一部分,我正在尝试让我的代码将一个数组索引与另一个数组索引“同步”。出现的问题是,当我重复运行部分代码时,输入值后输出不会改变,例如: case 'b': CaseBPrompt(); for (t=0;t<350;t++) { int result2[350]; result2[t] = strcmp(blankSpace, parkingSpace[t])

我的程序链接中有完整的代码;请阅读,我这里的代码足够长,但不是全部:

作为评估的一部分,我正在尝试让我的代码将一个数组索引与另一个数组索引“同步”。出现的问题是,当我重复运行部分代码时,输入值后输出不会改变,例如:

case 'b':

    CaseBPrompt();

    for (t=0;t<350;t++) {
        int result2[350];
        result2[t] = strcmp(blankSpace, parkingSpace[t]); // determine if the value of parkingSpace is the same as strcmp "empty"
        Synchronise(t);

        if (result2[t] == 0) { // if value of parkingSpace == "empty"
            // use spaceNumber; sync int variable w/array index
            LevelPrint(t);

            strcpy(carCustomer[t], customerName);
            // copy value of car number to index
            strcpy(parkingSpace[t], carNumber); // omit array index to ensure this can run
            break; // required, as will print other available spaces otherwise
        }

    }
    printf("You will take %s's car\n", carCustomer[t]);
    printf("Please drive the car over to %c%d\n", level, spaceNumber[t][3]);
break;
当我运行代码时,我收到以下输出:

empty
350
25
Please write car number (without spaces):
b

b
Valet options (press the corresponding letter to select):
a) Check available spaces
b) Park a customer's car
c) Retrieve a customer's car
q) Exit the program
Your choice: b
You have chosen to park a customer's car
Please input the customer's name, using _ in lieu of a space
b
Please input the values of the number plate
b
There is an available space at parking space A1
You will take b's car
Please drive the car over to A1
Valet options (press the corresponding letter to select):
a) Check available spaces
b) Park a customer's car
c) Retrieve a customer's car
q) Exit the program
Your choice: b
You have chosen to park a customer's car
Please input the customer's name, using _ in lieu of a space
b
Please input the values of the number plate
b
There is an available space at parking space **A1**
You will take b's car
Please drive the car over to **A1**
Valet options (press the corresponding letter to select):
a) Check available spaces
b) Park a customer's car
c) Retrieve a customer's car
q) Exit the program
Your choice: c
You have chosen to retrieve a customer's car
Please write their name, again with _ in lieu of a space:
c
Please write down what was on their number plate:
90jda
c's car is at **1**.
Valet options (press the corresponding letter to select):
a) Check available spaces
b) Park a customer's car
c) Retrieve a customer's car
q) Exit the program
Your choice:
我所关心的是输出中用星号包围的字符,因为在我在
案例“c”
下添加代码之前,
案例b
下的代码可以正确打印。我正在使用DevC++,我想知道我的代码是否有问题

当我再次选择选项B时,代码会在每次迭代之前打印A2、A3等,而选项C输出下显示的是149的值,因为我在
parkingSpace[150][3]
下预先分配了
90jda


parkingSpace
下的值用于与
case'b
blankSpace
同步,并在其
for
循环中打印出可用空间。对于
case'c'
parkingSpace
意味着与用户输入
carNumber
中包含相同字符串的任何索引同步,这在
case'c'
下的
For
循环的开头进行了比较
我相信我已经解决了它,这是因为我在数组中声明的一个值不相同;程序没有返回错误,因为这两个变量都被声明为整数变量

您真的需要大量的代码和文本才能在这里发布您的问题吗?为什么要将
result2
声明为数组?您只使用其中一个元素。考虑使用<代码>结构> <代码> s,而不是多个数组。我声明它是一个数组,因为它们将处理循环中每个数组值的比较结果。@ MarcMonis,如果您只使用一个结构数组,而不是单独的数组,您不需要同步任何内容。所有相关数据都集中在一个数组元素中。
empty
350
25
Please write car number (without spaces):
b

b
Valet options (press the corresponding letter to select):
a) Check available spaces
b) Park a customer's car
c) Retrieve a customer's car
q) Exit the program
Your choice: b
You have chosen to park a customer's car
Please input the customer's name, using _ in lieu of a space
b
Please input the values of the number plate
b
There is an available space at parking space A1
You will take b's car
Please drive the car over to A1
Valet options (press the corresponding letter to select):
a) Check available spaces
b) Park a customer's car
c) Retrieve a customer's car
q) Exit the program
Your choice: b
You have chosen to park a customer's car
Please input the customer's name, using _ in lieu of a space
b
Please input the values of the number plate
b
There is an available space at parking space **A1**
You will take b's car
Please drive the car over to **A1**
Valet options (press the corresponding letter to select):
a) Check available spaces
b) Park a customer's car
c) Retrieve a customer's car
q) Exit the program
Your choice: c
You have chosen to retrieve a customer's car
Please write their name, again with _ in lieu of a space:
c
Please write down what was on their number plate:
90jda
c's car is at **1**.
Valet options (press the corresponding letter to select):
a) Check available spaces
b) Park a customer's car
c) Retrieve a customer's car
q) Exit the program
Your choice: