Sustituir \ por salto linea en fichero
Publicado por Gustavo (1 intervención) el 23/11/2006 16:44:18
Necesito leer un fichero y crear otro pero sustituyendo el caracter \ del original por una salto de linea.
como puedo hacer la comparacion
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include<string.h>
void main (int argc, char *argv[])
{
FILE *fp,*out;
char letra;
if(argc!=2)
{
printf("Error");
exit(0);
}
if((fp=fopen(argv[1],"rw"))==NULL)
{
printf("%s %s",argv[1],fp);
printf("No se pudo abrir Archivo");
exit(1);
}
if((out=fopen("nuevo.txt","w"))==NULL)
{
printf("No creo");
fclose(fp);
exit(1);
}
while (!feof(fp))
{
fread(&letra,sizeof letra,1,fp);
if (letra=="\")
{
fwrite("\n",2,1,out);
printf ("IGUAL");
}
else
{
fwrite(&letra,sizeof letra,1,out);
}
}
fclose(fp);
fclose(out);
}
como puedo hacer la comparacion
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include<string.h>
void main (int argc, char *argv[])
{
FILE *fp,*out;
char letra;
if(argc!=2)
{
printf("Error");
exit(0);
}
if((fp=fopen(argv[1],"rw"))==NULL)
{
printf("%s %s",argv[1],fp);
printf("No se pudo abrir Archivo");
exit(1);
}
if((out=fopen("nuevo.txt","w"))==NULL)
{
printf("No creo");
fclose(fp);
exit(1);
}
while (!feof(fp))
{
fread(&letra,sizeof letra,1,fp);
if (letra=="\")
{
fwrite("\n",2,1,out);
printf ("IGUAL");
}
else
{
fwrite(&letra,sizeof letra,1,out);
}
}
fclose(fp);
fclose(out);
}
Valora esta pregunta


0