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:

#include <stdio.h>;
#include <stdlib.h>;

struct {
	char make[10];
	char model[10];
	double cost;
	int yearMade;
       }cars;

int main ()
{
FILE *myCars;
char cars[200];

myCars = fopen.........
.......................

THANKS :)

Recommended Answers

All 7 Replies

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.

well i aint got any c books,if i did i would know what to do:D.what can i use then then as my tutor was recommending the "gets" statement?

>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.

commented: "let me google that for you"- Cool site :) +1

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

;)

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...
;)

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.

thanks guys :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.