Go Back   PCMech Forums > Help & Discussion > Web Design / Development

Need Some Help? Type Your Keywords Here:

Reply
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Old 05-18-2005, 11:57 AM   #1
Member (9 bit)
 
Join Date: Nov 2002
Posts: 502
Working with files in C

I need to create a program that stores information in a file, then recover the inf to print it, make a search and delete x registry,

I created the program to make the file

# include
# include
# include

struct {

int codigo;
char marca [30];
char modelo [20];
int year; }vehiculo;


void main ()
{

FILE *car;

car = fopen("A:\\carros.dat","w");
fclose (car);
printf ("archivo carros creados");

getchar();
}

and this one to open the file to write

#include
#include
#include

struct {
int codigo;
char marca [30];
char modelo [20];
int year; } vehiculos;

void main()
{
printf ("\n ingrese el codigo un entero: ");
scanf ("%d",&vehiculos.codigo);
printf ("\n ingrese la marca: ");
gets (vehiculos.marca);
printf ("\n ingrese el modelo: ");
gets (vehiculos.modelo);
printf ("\n ingrese el year: ");
scanf ("%d",&vehiculos.year);
clrscr ();

FILE *car;
car = fopen ("a:\\carros.dat","w");
fwrite (&carros,sizeof(carros),1,car);
fclose (car);

printf ("\n Datos ingresados);

}

but the second one stops at the FILE *car; line

anybody has suggestions, is there a site that explans how to accomplish this?
note that I made a google search and find a manual in which is based the prog.

the libraries included are stdio.h conio.h and string.h
easg is offline   Reply With Quote
Old 05-18-2005, 01:02 PM   #2
Member (9 bit)
 
Join Date: Feb 2005
Posts: 392
the program stops because of "scanf()" function does not read the end of line! To make it go, you have to have a line like so:

--------------------
put a line:
getchar();
after the "scanf()"
-------------------
or
------------------
char chx;
while((chx=getch()) !='\n') {}
--------------------------------
or
while ((chx = getchar()) != '\n' && ch != EOF);
-----------------------
alfie2 is offline   Reply With Quote
Reply

Bookmarks

Still Need Help? Type Your Keywords Here:


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 07:23 AM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
SEO by vBSEO 3.6.0 PL2