|
以下のプログラムに
add,r1,r2,r3
add,r4,r5,r6
add,r7,r8,r9
add,r1,r2,r3
add,r4,r5,r6
と入力すると、合計が5にならず0になります。
どうしてでしょうか。
教えてください。
#include <stdio.h>
struct youso{ /* 構造体の宣言 */
char opecode[20];
char operand0[20];
char operand1[20];
char operand2[20];
};
int goukei(int x);
int main(int argc, char *argv[])
{
int count=0;
count=goukei(count);
printf("合計は%dです\n",count);
return 0;
}
int goukei(int count)
{
int i;
struct youso y[20]; /* 構造体変数と構造体配列の宣言 */
/* 構造体配列に scanf()でデータを入力 */
for(i = 0; i < 5; i++) {
scanf("%s", &y[i].opecode);
scanf("%s", &y[i].operand0);
scanf("%s", &y[i].operand1);
scanf("%s", &y[i].operand2);
/* 入力データの確認 */
if(i==0){
printf("opecode:%s operand0:%s operand1:%s operand2:%s\n",
y[i].opecode, y[i].operand0, y[i].operand1, y[i].operand2);
}else{
printf("opecode:%s operand0:%s operand1:%s operand2:%s p_opecode:%s\n",
y[i].opecode, y[i].operand0, y[i].operand1, y[i].operand2, y[i-1].opecode);
}
/* オペコード */
if(y[i].opecode=="add"){
printf("%dです\n",count+1);
count=count+1;
}else if(y[i].opecode=="sub"){
printf("%dです\n",count+2);
count=count+2;
}else if(y[i].opecode=="addi"){
printf("%dです\n",count+3);
count=count+3;
}else if(y[i].opecode=="addu"){
printf("%dです\n",count+4);
count=count+4;
}else if(y[i].opecode=="subu"){
printf("%dです\n",count+5);
count=count+5;
}else if(y[i].opecode=="addiu"){
printf("%dです\n",count+6);
count=count+6;
}else if(y[i].opecode=="mfco"){
printf("%dです\n",count+7);
count=count+7;
}else if(y[i].opecode=="mult"){
printf("%dです\n",count+8);
count=count+8;
}else if(y[i].opecode=="multu"){
printf("%dです\n",count+9);
count=count+9;
}else if(y[i].opecode=="div"){
printf("%dです\n",count+10);
count=count+10;
}else if(y[i].opecode=="divu"){
printf("%dです\n",count+11);
count=count+11;
}else if(y[i].opecode=="mfhi"){
printf("%dです\n",count+12);
count=count+12;
}else if(y[i].opecode=="mflo"){
printf("%dです\n",count+13);
count=count+13;
}else if(y[i].opecode=="and"){
printf("%dです\n",count+14);
count=count+14;
}else if(y[i].opecode=="or"){
printf("%dです\n",count+15);
count=count+15;
}else if(y[i].opecode=="andi"){
printf("%dです\n",count+16);
count=count+16;
}else if(y[i].opecode=="ori"){
printf("%dです\n",count+17);
count=count+17;
}else if(y[i].opecode=="sll"){
printf("%dです\n",count+18);
count=count+18;
}else if(y[i].opecode=="srl"){
printf("%dです\n",count+19);
count=count+19;
}else if(y[i].opecode=="lw"){
printf("%dです\n",count+20);
count=count+20;
}else if(y[i].opecode=="sw"){
printf("%dです\n",count+21);
count=count+21;
}else if(y[i].opecode=="lbu"){
printf("%dです\n",count+22);
count=count+22;
}else if(y[i].opecode=="sb"){
printf("%dです\n",count+23);
count=count+23;
}else if(y[i].opecode=="lui"){
printf("%dです\n",count+24);
count=count+24;
}else if(y[i].opecode=="beq"){
printf("%dです\n",count+25);
count=count+25;
}else if(y[i].opecode=="bne"){
printf("%dです\n",count+26);
count=count+26;
}else if(y[i].opecode=="slt"){
printf("%dです\n",count+27);
count=count+27;
}else if(y[i].opecode=="slti"){
printf("%dです\n",count+28);
count=count+28;
}else if(y[i].opecode=="sltu"){
printf("%dです\n",count+29);
count=count+29;
}else if(y[i].opecode=="sltiu"){
printf("%dです\n",count+30);
count=count+30;
}else if(y[i].opecode=="j"){
printf("%dです\n",count+31);
count=count+31;
}else if(y[i].opecode=="jr"){
printf("%dです\n",count+32);
count=count+32;
}else if(y[i].opecode=="jal"){
printf("%dです\n",count+33);
count=count+33;
}else{
printf("%dです\n",count);
}
}
return count;
}
|