THis program is an inventory program, the first time u run it it creats a file to store the inventory, but after you exit the program and run it again as soon as you enter a code for anything it crashes, can anyone fix it or tell me how to fix it???
THis program is an inventory program, the first time u run it it creats a file to store the inventory, but after you exit the program and run it again as soon as you enter a code for anything it crashes, can anyone fix it or tell me how to fix it???
> #define clrscr() system("cls")
Strike 1.
> void main()
Strike 2.
> can anyone fix it or tell me how to fix it???
A. I'm sure quite a few could.
B. Code it without errors.
Possibly, you should scan the file yourself, and mess around with functions by themselves. Independtly try to figure out exactly where you're going wrong. Culture functions out of your large program, and get them into smaller programs by themselves. Use the "singling out" method. Then, once you think you have pin-pointed the possible error, try and fix it yourself. If you need help with the discovered problematic area, post the code for troubleshooting.
Last edited by Shadow; 05-22-2002 at 07:05 PM.
The world is waiting. I must leave you now.
It has no ERRORS!!!!!!!
when i run it without the file created already it works perfect!!!!! it just crashes when the file is there!!!!
and i loked at the debugger and it showed that it was crashing whenever you entered the code field.
> it just crashes when the file is there!!!!
That's odd. It works just fine for me.
Though, it doesn't write to the file, and you should have an option to stop entering products, and return to the menu.
[EDIT]
Now that i've reread the posts, I noticed something.
> B. Code it without errors.
> > It has no ERRORS!!!!!!!
> when i run it without the file created already it works perfect!!!!! it just crashes when the file is there!!!!
That seems like an "error" to me.
[/EDIT]
Last edited by Shadow; 05-22-2002 at 09:12 PM.
The world is waiting. I must leave you now.
Well, it's a shot in the dark, but:
Code:In_File = fopen("Inventory.dat", "r+b"); //opening in binary mode for read/write if (In_File == NULL) { printf("\n\nFile does not exist: Creating file"); In_File = fopen("Inventory.dat", "w+b"); //creation in binary mode
..."r+b" should be "r+", and "w+b" should be "w+"....
I honestly don't have the time to debug it for you, but I can tell you that you're not far from completion - just keep at it.
Good luck.
Code:#include <cmath> #include <complex> bool euler_flip(bool value) { return std::pow ( std::complex<float>(std::exp(1.0)), std::complex<float>(0, 1) * std::complex<float>(std::atan(1.0) *(1 << (value + 2))) ).real() < 0; }
i tried r+ and w+, and it still crashes but thanx for trying to help, maybe it is just my comp and it might work on another, but thanx for all the help guys
I see you are using: fflush(stdin). This is wrong (see thread)
I'm not sure if this works on every compiler. Personally I prever:Code:head=work=(struct linven *)malloc(sizeof(struct linven));Code:head=(struct linven *)malloc(sizeof(struct linven)); work = head;Always check return values:Code:fread(work,sizeof(struct finven),1,In_File);
Code:if(fread(work,sizeof(struct finven),1,In_File) != 1) /* do something */Again check your return values:Code:work->next=(struct linven *)malloc(sizeof(struct linven));
B.t.w. I'ts working perfect on my machine. Nice piece of work!Code:if((work->next=(struct linven *)malloc(sizeof(struct linven))) == NULL) /* do something */
thanx!!!!
but i got to get it to work on mine cause i its a project for school!!!!!
If it's still broken, post your latest attempt (only the suspect bit at first).Originally posted by mattyans
thanx!!!!
but i got to get it to work on mine cause i its a project for school!!!!!
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]
Here is a program I think that will help.
A example of course hope it helps you.
Last edited by speedster; 05-23-2002 at 03:32 PM.
Speedster, don't use void main.
If it's not your program, don't post void main programs.
Why?
Simply,
If you're too lazy to say int main .... return 0;, then what else are you to lazy to do?
The world is waiting. I must leave you now.
Yes, assignments such as this are valid and will work on all compilers.I'm not sure if this works on every compiler. Personally I prever:
a = b = c;
This is valid. While it may not be clear to everyone what happens, it is perfectly valid. In this case, c is assigned to b, which is in turn assigned to a.
Quzah.
Hope is the first step on the road to disappointment.
here is the latest attempt
still same problem
>void main()
You're still persisting with this? Make it int main(void).
>while(!feof(In_File))
This won't work properly in all cases. You need to check the return from fread().
>In_File = fopen("Inventory.dat", "wb");
You should check this opened successfully before using it.
>fflush(stdin);
Good grief.....
>(struct linven *)malloc(sizeof(struct linven));
cast the return from malloc isn't needed, don't do it.
>scanf("%f", &work->price);
Always check the return code from this function to ensure you read correct data.
>In_File = fopen("Inventory.dat", "r+");
I believe that depending on your compiler, you'll probably want "rb" here. You certainly don't want r+, as this is read/write mode, and you're only reading.
>head=work=(struct linven *)malloc(sizeof(struct linven));
>fread(work,sizeof(struct finven),1,In_File);
This is also wrong. You are malloc'ing memory sizeof linven, then within fread you are loading the number of bytes used by struct finven. Make your mind up which one it should be! You also have the same problem on the write, and in the add_record() function. I think you have your two structures muddled up.
If you're having trouble with it crashing, put a few printf() statements in convenient places to help pin point the line of code that is killing it. But I suggest you fix the above lot first.
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]
> But I suggest you fix the above lot first.
Yes, review this thread a great deal.
Refer to man pages, FAQS, and google trying to solve / fix all of the above suggestions.
Maybe it's just me ( ? ), but, you seem to rush frantically to fix your code. It seems as if your taking the suggestions, and frantically putting them to work without taking your time to slowly understand things. I mean, poor ol' Hammer sounds like a broken record.
If this isn't the case, then woops, I made a faulty assumption.
Quote from hammer:
> If it's still broken, post your latest attempt (only the suspect bit at first).
You post the entire code.
> but i got to get it to work on mine cause i its a project for school!!!!!
We have all displayed the generousity to help with a topc that is mainly shunned.
Now, as I review the thread once more
> maybe it is just my comp and it might work on another, but thanx for all the help guys
...not once do I hear you mention the intended OS, and compiler you are using.
[edit]
To be clear, this information would be vital to us atleast getting the thing up and running.
[/edit]
Judging by your #define clrscr() = system("cls"); call, or there-abouts, I would say your compiling on windows.
Yes?
What compiler?
It shouldn't be "your computer"...that's an irrelevant issue. What matters is your OS and compiler, which have not yet been confirmed.
BTW, the proper way to use comments in C is:
/* Comments */
Not:
// Comments
The 2nd one is C++.
Last edited by Shadow; 05-23-2002 at 06:22 PM.
The world is waiting. I must leave you now.