is my program ok? i don't really know where to change my coding. please help me. especially at that void main { .
it would be great if you guys include some explaination for my problem here. :cool:
btw, in my program i have to be able to do a selection ADD which is add a child data such as name,id,age,weight and lastly at the gender boy or girl ,i have to put boy and girl into txt file respectively.so that at the selection 4 EXIT,the user will be getting boy.txt and girl.txt file. i used strcmp but not sure if it would work. help thnkss

12-22-2011

laserlight

Please post your code in [code][/code] bbcode tags instead. You should also state how exactly does your program not work, e.g., what are the error messages.

printf("You are printing child.txt list");
thefile=fopen("child.txt","w+");
break;
case EXIT:
printf("Thank you. The child details are being written into boy.txt and girl.txt.Please find the file in the same folder as this program.");
if strcmp (kids[i].gender == "boy")
boyfile=fopen("boy.txt","w");
else
girlfile=fopen("girl.txt","w");
break;
}

i got errors like 'main' : local function definitions are illegal and something like" expected a ';' "

12-22-2011

laserlight

Quote:

Originally Posted by liyana21

this is a C++ program.

Okay, but I note that you are not using the C++-style equivalents for I/O and strings.

Quote:

Originally Posted by liyana21

i got errors like 'main' : local function definitions are illegal and something like" expected a ';' "

Indent your code properly. These errors are likely because you have written functions within other functions, in turn because your code is too messy for you (and me) to handle.

12-22-2011

Elysia

Quote:

Originally Posted by liyana21

this is a C++ program.

I note that this is entirely C, and not a hint of C++.
Why do you think this is C++? Is this what someone has told you (eg teacher, tutorial)?
What are you really wanting to learn--C or C++?

12-22-2011

brewbuck

For starters, remove these lines at the beginning which are screwing things up:

Code:

void red(enum selection s)
{

12-22-2011

iMalc

Regardless of the file extension being .cpp and not .c, this is a broken C program, not a C++ program.
A C++ compiler can compile some C code and it just so happens that what you've written is largely acceptable to a C++ compiler.

You wont get much more help until you've acted on what you've already been told. I.e. change void main to int main, and indent the code properly etc.

break;
case 3:
printf("You are printing child.txt list");
thefile=fopen("child.txt","w+");
break;
case 4:
printf("Thank you. The child details are being written into boy.txt and girl.txt.Please find the file in the same folder as this program.");
if (!strcmp(kids[i].gender, "boy"))
boyfile=fopen("boy.txt","w");
else
girlfile=fopen("girl.txt","w");
break;

}
{
fclose(thefile);
}
fclose(boyfile);
{
fclose(girlfile);
}
}
}

12-23-2011

liyana21

now i'm using int main () , then i erased that void red(enum selection s) for simple plain enumeration. btw,i'm learning C++ program so sorry for confusing you guys cos i'm not that good yet in C++. right now, i could already run my program. however my loop keep on looping and wont stop. infinitely. so where did i go wrong now?? please help. thanks :D

12-23-2011

Elysia

You still need to properly indent the code (google it!).
And you haven't answered my question yet. C or C++?

12-24-2011

Rodaxoleaux

Quote:

Originally Posted by Elysia

You still need to properly indent the code (google it!).
And you haven't answered my question yet. C or C++?

Quote:

Originally Posted by liyana21

this is a C++ program.

Although every statement in the code provided is C.

12-24-2011

brewbuck

This thread is depressing. A lot of misdirected criticism, no actual help. Yes, the code is calling some C IO functions. Big whoop.