F
F?bio Botelho
Sorry About the english....
This program copy one file to another , but when i run it it's
gives-me an error:
Segmentation fault
I don't understand ... because it pass my test : opens the first file
and create the second.
If any one could give me a help I would be apreciated.
thanks.
Fábim
#include <stdio.h>
#include <stdlib.h>
main(int argc, char *argv[])
{
FILE *fp,*fd;
int ch;
if (argc!=3)
{
printf("Sintaxe:\n\n%s ficheiro-fonte ficheiro-destino\n",argv[0]);
exit(1);
}
fp=fopen(argv[1],"rb");
if (fp=NULL)
{printf("Ficheiro: %s Não válido!\n",argv[1]);
exit(2);}
fd=fopen(argv[2],"wb");
if (fd=NULL)
{
printf("Impossivel criar o ficheiro %s \n",argv[2]);
exit(3);
}
while (( ch = fgetc(fd) )!=EOF)
fputc(ch,fd);
fclose(fd);
fclose(fd);
}
This program copy one file to another , but when i run it it's
gives-me an error:
Segmentation fault
I don't understand ... because it pass my test : opens the first file
and create the second.
If any one could give me a help I would be apreciated.
thanks.
Fábim
#include <stdio.h>
#include <stdlib.h>
main(int argc, char *argv[])
{
FILE *fp,*fd;
int ch;
if (argc!=3)
{
printf("Sintaxe:\n\n%s ficheiro-fonte ficheiro-destino\n",argv[0]);
exit(1);
}
fp=fopen(argv[1],"rb");
if (fp=NULL)
{printf("Ficheiro: %s Não válido!\n",argv[1]);
exit(2);}
fd=fopen(argv[2],"wb");
if (fd=NULL)
{
printf("Impossivel criar o ficheiro %s \n",argv[2]);
exit(3);
}
while (( ch = fgetc(fd) )!=EOF)
fputc(ch,fd);
fclose(fd);
fclose(fd);
}