Really? Get a new school. Ask if you can use fgets().for school i have to use gets()
Really? Get a new school. Ask if you can use fgets().for school i have to use gets()
dwk
Seek and ye shall find. quaere et invenies.
"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell
Other boards: DaniWeb, TPS
Unofficial Wiki FAQ: cpwiki.sf.net
My website: http://dwks.theprogrammingsite.com/
Projects: codeform, xuni, atlantis, nort, etc.
so i have to change the value of fp before i do fclose(fp)? if so what value does it need? and ya why would fp equaling NULL cause fclose() to crash?
hooch
Look, just put the fclose(fp) right here:
And don't use while(!feof()); see the FAQCode:if(fp = fopen(filename,"r+")== NULL)//ERROR 1 { printf("CANNOT OPEN FILE\n"); } else { //fp = fopen(filename,"r+"); fscanf(fp,"%d%s%s%c%f%d",records[elementsize].cust_id, records[elementsize].cust_name, records[elementsize].state, records[elementsize].dis_code, records[elementsize].balance, records[elementsize].outstanding_orders); while(!feof(fp)) { elementsize++; fscanf(fp,"%d%s%s%c%f%d",records[elementsize].cust_id, records[elementsize].cust_name, records[elementsize].state, records[elementsize].dis_code, records[elementsize].balance, records[elementsize].outstanding_orders); } fclose(fp); }
dwk
Seek and ye shall find. quaere et invenies.
"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell
Other boards: DaniWeb, TPS
Unofficial Wiki FAQ: cpwiki.sf.net
My website: http://dwks.theprogrammingsite.com/
Projects: codeform, xuni, atlantis, nort, etc.
i put the fclose(fp) right there and it still crashes why does C file handling have to be so much more confusing than C++ argh....
and well one other reason i beleive the school uses gets is cause they dont really concern themselves with tricks that are better for certain langauges rather they are trying to use a more generic method for most langauges though i think he is going to start showing us fgets() as we get more into C file handling so im sure ill sure it sooner or later or when i look at these faqs a bit more and worry about more effecient C programming.
hooch
How about some address operators and using the proper format specifier for double
Make sure your file only has upto 12 entriesCode:fscanf(fp, "%d %s %s %c %lf %d\n",&records[elementsize].cust_id, records[elementsize].cust_name, records[elementsize].state, &records[elementsize].dis_code, &records[elementsize].balance, &records[elementsize].outstanding_orders)
Code:records[12]
Last edited by spydoor; 02-27-2006 at 09:34 PM.
still doesnt seem to work for some reason damnit guess ill just ask teacher later cause ive been sick so i didnt goto school today oh well i gotta go out tommorrow for stuff anyway might see if hes there. stupid file opening argh.
theres actually only 8 records but was told make an array a little bigger so it can hold 1 or 2 more records
hooch
Post your updated code so we can see the fscanf calls. You keep forgetting your ampersands (&).
dwk
Seek and ye shall find. quaere et invenies.
"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell
Other boards: DaniWeb, TPS
Unofficial Wiki FAQ: cpwiki.sf.net
My website: http://dwks.theprogrammingsite.com/
Projects: codeform, xuni, atlantis, nort, etc.
Man you guys and your ugly switch menus. You mean to tell me schools can't teach a better way to do this?
Schools seem to take all the necessary tools for the job and put a lock on them, thus making you use some arcane method and use 150 lines when if you just used the right tool, you could do it AND more in about 30 lines.
I just don't understand it.
stupid & that was the problem lol. i suppose one of you could tell me why i need that and this here book failed to mention that?
and yes i keep hearing that schools have a hard time preparing you of course i also hear real life programs our millions of lines and done in teams something schools cant effectively do so who knows why schools do what they do. but ya programming does have this insane method of being hard to learn cause no one teaches the basics very well and coming from a guy who has self taught himself mostly i can tell you its next to impossible to get a proper tutorial or anything and even in HS when they finnally had programming the teacher's idea of teaching was "is this correct hairy"....the student in the class that actually understood it all
hooch
Originally Posted by ssjnamek
Not all real world programs are millions of lines of code done in teams.
I could be mean-spirited and say that schools don't prepare you well because the folks who are teaching you are teachers and not really programmers, but that would not be a fair statement necessarily.
As an aside, my stepdaughter (who's a semester away from a BS in Ed, going to be a math teacher) had to do a CS intro to programming class a few semesters back. The professor used Java -- okay, I know a bit of Java and could help. The only problem was that the prof spent all kinds of time talking about objects, inheritance, and stuff like that, before ever mentioning control structures or anything that pertains to programming.
I was fortunate -- I learned assembler first (on my own) and ended up programming in C with a really good mentor.
Read other people's code, if you can get your hands on it. Don't be afraid to take a program you have written (that works) and look at it and say "How can I make this better?" "Is there a better technique than what I have used?"
Get a copy of K&R. Okay, I"m old fashioned, but that book, to me, is the starting point.
Frequent this forum and others -- read the topics that are here, and look at the code that people post and see if you can find what is wrong. (Hell, I've been programming in C for 20 years now and I still learn stuff in here)
That will make you a better programmer..... that and lots of hard work
Mr. Blonde: You ever listen to K-Billy's "Super Sounds of the Seventies" weekend? It's my personal favorite.