このコードが file.txt に保存されている単語から始まらない理由を知りたいです。
コードはコンパイルされますが、エラーが見つかりません
関数「scanf」が文字をキャプチャして変数に渡すのに失敗したのはなぜだろうか
返信ありがとうございます
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
int a = 0;
int b = 0;
int c = 0;
int d = 0;
int e = 0;
int f = 0;
int g = 0;
int h = 0;
char var[] = { '1', 'A', '2', 'B', '3', 'C', '4', 'D', '5', 'E', '6' };
char caracteres[9];
char caracteres_txt[9];
FILE *fp, *sesion;
sesion = fopen("Save_Sesion.txt", "r");
if (sesion == NULL)
{
printf("\nNo sesion saved.\n");
}
else
{
printf("\nlast word was:\n\n");
fgets(caracteres, 9, sesion);
printf("%s\n", caracteres);
fscanf(sesion, "%s", caracteres_txt);
}
if (caracteres_txt[1] == var[0])
{
a = 0;
}
else
{
if (caracteres_txt[1] == var[1])
{
a = 1;
}
else
{
if (caracteres_txt[1] == var[2])
{
a = 2;
}
else
{
if (caracteres_txt[1] == var[3])
{
a = 3;
}
else
{
if (caracteres_txt[1] == var[4])
{
a = 4;
}
else
{
if (caracteres_txt[1] == var[5])
{
a = 5;
}
else
{
if (caracteres_txt[1] == var[6])
{
a = 6;
}
else
{
if (caracteres_txt[1] == var[7])
{
a = 7;
}
else
{
if (caracteres_txt[1] == var[8])
{
a = 8;
}
else
{
if (caracteres_txt[1] == var[9])
{
a = 9;
}
else
{
if (caracteres_txt[1] == var[10])
{
a = 10;
}
}
}
}
}
}
}
}
}
}
}
if (caracteres_txt[2] == var[0])
{
b = 0;
}
else
{
if (caracteres_txt[2] == var[1])
{
b = 1;
}
else
{
if (caracteres_txt[2] == var[2])
{
b = 2;
}
else
{
if (caracteres_txt[2] == var[3])
{
b = 3;
}
else
{
if (caracteres_txt[2] == var[4])
{
b = 4;
}
else
{
if (caracteres_txt[2] == var[5])
{
b = 5;
}
else
{
if (caracteres_txt[2] == var[6])
{
b = 6;
}
else
{
if (caracteres_txt[2] == var[7])
{
b = 7;
}
else
{
if (caracteres_txt[2] == var[8])
{
b = 8;
}
else
{
if (caracteres_txt[2] == var[9])
{
b = 9;
}
else
{
if (caracteres_txt[2] == var[10])
{
b = 10;
}
}
}
}
}
}
}
}
}
}
}
if (caracteres_txt[3] == var[0])
{
c = 0;
}
else
{
if (caracteres_txt[3] == var[1])
{
c = 1;
}
else
{
if (caracteres_txt[3] == var[2])
{
c = 2;
}
else
{
if (caracteres_txt[3] == var[3])
{
c = 3;
}
else
{
if (caracteres_txt[3] == var[4])
{
c = 4;
}
else
{
if (caracteres_txt[3] == var[5])
{
c = 5;
}
else
{
if (caracteres_txt[3] == var[6])
{
c = 6;
}
else
{
if (caracteres_txt[3] == var[7])
{
c = 7;
}
else
{
if (caracteres_txt[3] == var[8])
{
c = 8;
}
else
{
if (caracteres_txt[3] == var[9])
{
c = 9;
}
else
{
if (caracteres_txt[3] == var[10])
{
c = 10;
}
}
}
}
}
}
}
}
}
}
}
if (caracteres_txt[4] == var[0])
{
d = 0;
}
else
{
if (caracteres_txt[4] == var[1])
{
d = 1;
}
else
{
if (caracteres_txt[4] == var[2])
{
d = 2;
}
else
{
if (caracteres_txt[4] == var[3])
{
d = 3;
}
else
{
if (caracteres_txt[4] == var[4])
{
d = 4;
}
else
{
if (caracteres_txt[4] == var[5])
{
d = 5;
}
else
{
if (caracteres_txt[4] == var[6])
{
d = 6;
}
else
{
if (caracteres_txt[4] == var[7])
{
d = 7;
}
else
{
if (caracteres_txt[4] == var[8])
{
d = 8;
}
else
{
if (caracteres_txt[4] == var[9])
{
d = 9;
}
else
{
if (caracteres_txt[4] == var[10])
{
d = 10;
}
}
}
}
}
}
}
}
}
}
}
printf("\nPress Enter to continue\n");
getchar();
while (a <= 10)
{
while (b <= 10)
{
while (c <= 10)
{
while (d <= 10)
{
while (e <= 10)
{
while (f <= 10)
{
while (g <= 10)
{
while (h <= 10)
{
printf("%c%c%c%c%c%c%c%c\n", var[a],
var[b], var[c], var[d], var[e],
var[f], var[g], var[h]);
++h;
}
h = 0;
++g;
}
g = 0;
++f;
}
f = 0;
++e;
}
e = 0;
++d;
fp = fopen("Save_Sesion.txt", "w");
fprintf(fp, "%c%c%c%c%c%c%c%c\n", var[a], var[b], var[c],
var[d], var[e], var[f], var[g], var[h]);
fclose(fp);
}
d = 0;
++c;
}
c = 0;
++b;
}
b = 0;
++a;
}
return 0;
}