المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : I/O files



C++ Programming
10-15-2009, 11:52 PM
Hello to everyone.

I want to read line by line an input file (leer_datos).

In the input file (leer_datos): If the first character of each line is '|', then I copy the whole line and paste it in an output file (escribir_datos).
In the input file (leer_datos): If the first character isn´t '|' then I go to the next line in the input file (leer_datos).

My code:


#include ;

int main(void)
{

FILE *leer_datos, *escribir_datos;
char muestra[50];

leer_datos = fopen("input_file.txt", "rt");
escribir_datos = fopen("output_file.txt", "wt");

while ( (!feof(leer_datos)) && (!ferror(leer_datos)) )

{
muestra = getc(leer_datos) ;
if (muestra == '|')
{
fgets(muestra, sizeof(muestra), leer_datos);
fputs(muestra, escribir_datos);
fputs("\n", escribir_datos);
}


}

if (fclose(leer_datos) != 0)
printf ("Hay problemas al cerrar el fichero de lectura de datos\n");

if (fclose(escribir_datos) != 0)
printf ("Hay problemas al cerrar el fichero de escritura de datos\n");

}





...but it gives some errors and I don´t sure about it works fine.
Anyone could help me, please!?.