我们在学校布置了一项作业,而代码末尾的while循环似乎没有给出我所期望的值。
#include <stdio.h>
#include <string.h>
int main() {
char str[50],storage[50][50]={0},temp[50]={0};
printf("Input Formula without space:");
gets(str);
int x=0, y=0,z=0,w,i,top=-1,max=strlen(str);
for(i=0;i<max;i++){
printf("Eyyyyyy");
top+=1;
switch(str[top]){
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '-':
case '+':
case '*':
case '/':
case '9':storage[x][y]=str[top];x++;break;
case ')':
if (x-3<0)
break;
else{
while(storage[x-3][y]!=0){
temp[y]=storage[x-3][y];
y++;
printf("Hey");};
storage[x-3][y]='(';
while (temp[y]!=0){
storage[x-3][y+1]=temp[y];
y++;
};
for (z=2;z>=0;z--){
while (storage[x-z][y]!=0){
w=strlen(storage[x-3]);
storage[x-3][w]=storage[x-z][y];
}
}
}
x-=3;
break;
}
}
for(i=0;i<20;i++){
printf("%c",storage[0][i]);
}
for(i=0;i<20:i++){
printf("%c",storage[0][i]);
}
while(storage[x][y]!=0){
printf("%c",storage[0][y]);
y++;
}
}我想寻求一些关于如何使while循环工作的帮助。编译时,它没有给我任何错误,只是值on while循环没有显示出来。只有在此之前的其他printf。
发布于 2020-12-12 09:13:03
关于发布代码末尾的while()语句:
while(storage[x][y]!=0){`x和y的初始值是什么
由于这些值已经达到最大值,因此选择的存储超过了数组‘storage[x][y]’的末尾。
建议在进入while()循环之前正确初始化这些索引值
https://stackoverflow.com/questions/65243915
复制相似问题