struct and file processing in C

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Nov 2008
Posts: 4
Reputation: valchid is an unknown quantity at this point 
Solved Threads: 0
valchid valchid is offline Offline
Newbie Poster

struct and file processing in C

 
0
  #1
Nov 21st, 2008
hi,can someone please tell me how i can read in data,save data to a file and print it out to the screen using the "gets" statement.My code starts something like:
  1. #include <stdio.h>;
  2. #include <stdlib.h>;
  3.  
  4. struct {
  5. char make[10];
  6. char model[10];
  7. double cost;
  8. int yearMade;
  9. }cars;
  10.  
  11. int main ()
  12. {
  13. FILE *myCars;
  14. char cars[200];
  15.  
  16. myCars = fopen.........
  17. .......................
THANKS
Last edited by Narue; Nov 21st, 2008 at 4:43 pm. Reason: added code tags
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,810
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 747
Team Colleague
Narue's Avatar
Narue Narue is online now Online
Senior Bitch

Re: struct and file processing in C

 
1
  #2
Nov 21st, 2008
So...did you even bother to read any book on C before running here?

>using the "gets" statement
Don't use gets, it's completely unsafe.
New members chased away this month: 3
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 4
Reputation: valchid is an unknown quantity at this point 
Solved Threads: 0
valchid valchid is offline Offline
Newbie Poster

Re: struct and file processing in C

 
0
  #3
Nov 21st, 2008
well i aint got any c books,if i did i would know what to do.what can i use then then as my tutor was recommending the "gets" statement?
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,810
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 747
Team Colleague
Narue's Avatar
Narue Narue is online now Online
Senior Bitch

Re: struct and file processing in C

 
2
  #4
Nov 21st, 2008
>well i aint got any c books
I would have more sympathy for you if the internet weren't a wealth of information. Yet you've bypassed all of the tutorials, references, and ebooks that are available, and gone with the worst possible first step: bothering other people with an easily researched question. Here, let me google that for you since you've already bothered me.

>what can i use then then
fgets. While you're googling, why not look up why gets is unsafe.

>as my tutor was recommending the "gets" statement?
And get a new tutor. Your current one is just clueless enough to ruin your future as a C programmer.
New members chased away this month: 3
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 4
Reputation: valchid is an unknown quantity at this point 
Solved Threads: 0
valchid valchid is offline Offline
Newbie Poster

Re: struct and file processing in C

 
0
  #5
Nov 21st, 2008
will have a good look at that.thought i would get a quick solution on here but thanks for your help anyway.

and my tutor did say i can use gets or fgets so i dont know why he said it

Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 2,001
Reputation: ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of 
Solved Threads: 343
ArkM's Avatar
ArkM ArkM is offline Offline
Postaholic

Re: struct and file processing in C

 
0
  #6
Nov 22nd, 2008
Originally Posted by valchid View Post
and my tutor did say i can use gets or fgets so i dont know why he said it
May be he is an inclined to sadism person. If so and if you are a latent masochist then use gets...
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 3,117
Reputation: WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of 
Solved Threads: 282
Moderator
WaltP's Avatar
WaltP WaltP is offline Offline
Posting Sensei

Re: struct and file processing in C

 
0
  #7
Nov 22nd, 2008
Here, let me help you with the gets()/fgets() question:
Click Here.

And I'm sure it's inevitable, he's going to do the same with scanf() , too, so:
Click Here too.
The 3 Laws of the Procrastination Society:
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 4
Reputation: valchid is an unknown quantity at this point 
Solved Threads: 0
valchid valchid is offline Offline
Newbie Poster

Re: struct and file processing in C

 
0
  #8
Nov 22nd, 2008
thanks guys
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for C
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC