Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Name: tImmaY
hey, i'm trying to write a little guessing game program that has a couple levels and stages and you can save / load where you are, but i'm having problems with the loading. i just tried debugging and when choose which saveslot to load, the program stops and i got this error: An Access Violation (Segmentation Fault) raised in your program.
the code for the load function is this:
void load()
{
FILE *file1, *file2, *file3;
int counter = 0;
int loadfile = 0;
printf("Which saveslot would you like to load from?\n1 - saveslot1\n2 - saveslot2\n3 - saveslot3\n::");
scanf("%d", loadfile);
switch(loadfile)
{
case 1 : file1 = fopen("saveslot1.shibby", "r");
fscanf(file1, "%s", level);
if(file1 == NULL)
{
printf("saveslot1 does not exist.");
}
else if (file1 != NULL)
{
printf("saveslot1 found, level: %s\n", level);
}
fclose(file1);
break;
case 2 : file2 = fopen("saveslot2.shibby", "r");
fscanf(file2, "%s", level);
if (strcmp(level, nul) == 0)
{
printf("saveslot2 does not exist.\n");
}
else if (file2 != NULL)
{
printf("saveslot2 found, level: %s\n", level);
}
fclose(file2);
break;
case 3 : file3 = fopen("saveslot3.shibby", "r");
fscanf(file3, "%s", level);
if (file3 == NULL)
{
printf("saveslot3 does not exist.\n");
}
else if (file3 != NULL)
{
printf("saveslot3 found, level: %s\n", level);
}
fclose(file3);
break;
}
printf("Would you like to load this level: %s\nyes or no: ", level);
while((pt=gets(loadlevel)) != NULL)
{
returnCode = puts(loadlevel);
if (returnCode == EOF)
{
printf("\nError on input.\n");
}
}
if (strcmp(loadlevel, no) == 0)
{
nope();
}
else if(strcmp(loadlevel, yes) == 0)
{
lvlchk(lvl);
}
else { printf("I'm sorry, %s is not a valid response.\n", loadlevel); start(menu, stage); }
}any ideas of whats causing the error? thank in advance

wow.. thanks to my AWESOME debugging skills, i figured it out. the problem was here:
scanf("%d", loadlevel);which should have been:
scanf("%d", &loadlevel);pssh.. why couldn't they have made storing int's easy in C instead of waiting for C++..pssh.

"pssh.. why couldn't they have made storing int's easy in C instead of waiting for C++..pssh."
- ...wtf?BlueRaja.admin@gmail.com

C++ came along after the programming world had been watered down by Visual Basic.
Be sure to come back and let us know if our suggestions helped!

yes, i know. it wasn't a literal question.. it was a "damn, that would have been easier 14 years earlier" kind of thing. lol

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |