Discuss C & C++ coding, and related things.
Offline
AHA!
Can you tell me what's wrong with my code?
if(save==1) {
printf("Saving your game...");
FILE *fopen(const char *sav.txt, const char *w);
fprintf(sav.txt,"%d","%s %s %s %s %s %s %s %d %d %d", &colorone, &colortwo, &cmark, &gen, &name, &place, &type, %placetwo, &placethree, &introread);
fclose(sav.txt);
fclose(sav.txt);
fclose(sav.txt);
printf("Save complete!");
save=0;
}
THANKS!
(Sorry, beginner coder taking advantage of topic)
Offline
Dinoclor wrote:
AHA!
Can you tell me what's wrong with my code?
if(save==1) {
printf("Saving your game...");
FILE *fopen(const char *sav.txt, const char *w);
fprintf(sav.txt,"%d","%s %s %s %s %s %s %s %d %d %d", &colorone, &colortwo, &cmark, &gen, &name, &place, &type, %placetwo, &placethree, &introread);
fclose(sav.txt);
fclose(sav.txt);
fclose(sav.txt);
printf("Save complete!");
save=0;
}
THANKS!
(Sorry, beginner coder taking advantage of topic)
Aha!
sorry, I don't know much about file I/O. What error do you get?
Offline
Wait a moment
if(save==1) {
printf("Saving your game...");
FILE *fopen(const char *sav.txt, const char *w);
fprintf(sav.txt,"%d","%s %s %s %s %s %s %s %d %d %d", &colorone, &colortwo, &cmark, &gen, &name, &place, &type, %placetwo, &placethree, &introread);
fclose(sav.txt);
printf("Save complete!");
save=0;
}
THIS is the code I was using.
At the time when the loop kicks in, it crashes. No compile error.
Offline
I don't know. I don't see any problems.
Offline
samtwheels wrote:
I don't know. I don't see any problems.
Neither do I, which is why I don't understand. Thanks anyway, I'll ask on devshed.
Offline
I'll post the whole thing here, I made a mistake. It DOESN'T crash when the loop kicks in.
Sorry -_-'
#include <stdio.h>
char colorone[10];
char colortwo[10];
char cmark[20];
char gen[20];
char name[55];
char place[10];
char type[15];
int placetwo = 0;
int placethree = 0;
int introread = 0;
int save = 0;
int main()
{
//Remember to add instructions and more stuff, fix place names AND a better name. AFTER PROGRAMMING.
printf("Welcome to gamename! Instructions COMING SOON!\n");
if(save==1) {
printf("Saving your game...");
FILE *fopen(const char *sav.txt, const char *w);
fprintf(sav.txt,"%d","%s %s %s %s %s %s %s %d %d %d", &colorone, &colortwo, &cmark, &gen, &name, &place, &type, %placetwo, &placethree, &introread);
fclose(sav.txt);
printf("Save complete!");
save=0;
}
if (introread == 0) {
printf("What is your name?\n");
scanf("%s", &name);
printf("Welcome to gamename, %s\n", &name);
printf("What is your cutiemark?\n");
scanf("%s", &cmark);
printf("Are you a pegasus, unicorn, or earth pony?\n");
scanf("%s", &type);
printf("What is your fur color?\n");
scanf("%s", &colorone);
printf("What is your hair color?\n");
scanf("%s", &colortwo);
printf("What is your gender?\n");
scanf("%s", &gen);
printf("Where do you want to live? CL, PV, or CL.\n");
scanf("%s", &place);
printf("In building 1, 2, 0r 3?\n\n");
scanf("%d", &placetwo);
//CRASHES RIGHT HERE
printf("You are %s. You live in building %d in %s. Your hair is %s and your fur is %s. Your cutiemark is a %s, you are a %s, and you are a %s." , &name, &placetwo, &place, &colortwo, &colorone, &cmark, &gen, &type);
printf("\nAre you happy with your character? 0 for no, 1 for yes.");
scanf("%d", &introread);
if(introread==1) {
save=1;
}
}
return 0;
}Don't laugh.
Last edited by Dinoclor (2011-12-03 14:42:56)
Offline