This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2011-12-03 14:17:18

samtwheels
Scratcher
Registered: 2011-03-20
Posts: 1000+

Official C and C++ Topic

Discuss C & C++ coding, and related things.

Offline

 

#2 2011-12-03 14:23:18

Dinoclor
Scratcher
Registered: 2010-06-10
Posts: 1000+

Re: Official C and C++ Topic

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)


This is a temporary signature. It will exist until I think of something witty.

Offline

 

#3 2011-12-03 14:25:16

samtwheels
Scratcher
Registered: 2011-03-20
Posts: 1000+

Re: Official C and C++ Topic

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

 

#4 2011-12-03 14:30:39

Dinoclor
Scratcher
Registered: 2010-06-10
Posts: 1000+

Re: Official C and C++ Topic

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.


This is a temporary signature. It will exist until I think of something witty.

Offline

 

#5 2011-12-03 14:34:52

samtwheels
Scratcher
Registered: 2011-03-20
Posts: 1000+

Re: Official C and C++ Topic

I don't know. I don't see any problems.

Offline

 

#6 2011-12-03 14:36:32

Dinoclor
Scratcher
Registered: 2010-06-10
Posts: 1000+

Re: Official C and C++ Topic

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.


This is a temporary signature. It will exist until I think of something witty.

Offline

 

#7 2011-12-03 14:39:06

Dinoclor
Scratcher
Registered: 2010-06-10
Posts: 1000+

Re: Official C and C++ Topic

I'll post the whole thing here, I made a mistake. It DOESN'T crash when the loop kicks in.
Sorry -_-'

Code:

#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)


This is a temporary signature. It will exist until I think of something witty.

Offline

 

#8 2011-12-03 15:20:44

samtwheels
Scratcher
Registered: 2011-03-20
Posts: 1000+

Re: Official C and C++ Topic

bump.

Offline

 

Board footer