Computing.Net > Forums > Programming > C error in Dev-C++

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

C error in Dev-C++

Reply to Message Icon

Name: tImmaY
Date: January 7, 2005 at 01:23:54 Pacific
OS: Windows XP Home SP2
CPU/Ram: AMD Athlon XP 2400+ / 512
Comment:

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



Sponsored Link
Ads by Google

Response Number 1
Name: tImmaY
Date: January 7, 2005 at 01:30:19 Pacific
Reply:

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.


0

Response Number 2
Name: BlueRaja
Date: January 8, 2005 at 16:30:38 Pacific
Reply:

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

BlueRaja.admin@gmail.com


0

Response Number 3
Name: tImmaY
Date: January 10, 2005 at 01:26:43 Pacific
Reply:

to store an int in C:
scanf("%d", &intVar);

to store an int in C++:
cin >> intVar;


0

Response Number 4
Name: Don Arnett
Date: January 10, 2005 at 15:03:29 Pacific
Reply:

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!


0

Response Number 5
Name: tImmaY
Date: January 10, 2005 at 15:30:16 Pacific
Reply:

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


0

Related Posts

See More



Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: C error in Dev-C++

Compiling Errors in Dev C++ www.computing.net/answers/programming/compiling-errors-in-dev-c-/9484.html

How to disable Windows errors in C www.computing.net/answers/programming/how-to-disable-windows-errors-in-c-/11257.html

C compile errors in vc++ www.computing.net/answers/programming/c-compile-errors-in-vc/4010.html