I am making a text quest game in C++ and it have choices like where to go or what to do. My teacher showed me how to write the game without cases and switches . Just in 2 whiles. It loads 1st text files then it displays text before it founds special line [goto] ( just spicial line) . and then the other "while" starts working . It shows us text and the number of variant of it. It is easy to make a txt quest game this way but there is 1 minus it loads txt with only digits. I made that 1st file is not digited and it has name, but i cant get it to work with choices that leads to another not digit file.
sorry 4 bad english . If u dont get how it works ill try to explain. We got the .cpp file(i work in codeblocks) and some txt near the cpp. the cpp code:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <cstdio>
#include <iostream>
int main()
{
setlocale(LC_ALL,"russian_russia");
char location[100]="a" ; // !!!
char filename[10]="a";
while(1 == 1 )
{
// !!!
strcat(filename, ".txt");
FILE *file = fopen(filename, "rt");
while(1==1)
{
char line[1001];
fgets(line, 1000, file);
fscanf(file, line); // !!!
if (strcmp(line,"[goto]\n") == 0)
{
break;
}
printf(line);
// !!!!
}
int t = 1;
char locsToGo[100];
while (1==1)
{
char line[1001];
fgets(line, 1000, file);
fgets(file, "%d\n", &locsToGo[t]);
if (strcmp(line,"[end]\n") == 0)
{
break;
}
printf("%d: %s", t, line);
t++;
}
char a='o'; //////Noob DEFENCE
while (!(a>='1' && a<='4'))//////Nooob DEFENCE
{
scanf("%c", &a);////////NOOOOB DEFENCE
}
int input = a-'0';
char location = locsToGo[input];
fclose(file);
}
}
and text file looks like:
text
[goto]
1st variant
12
2nd variant
13
[end]
so can you help me with my problem So i can do variants that leads to not digit filebut file with name like "b.txt"?
Edited by al0816, 17 October 2012 - 06:18 AM.






