|
|||||||
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
#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 |
|
|
|
|
|
#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); -----------------------
|
|
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|