Doubt program that copies from one file to another in C with functions

0

I have to do a job in C which makes copying from one file to another at launch time (on linux using argc and argv). I'm not very accustomed to file manipulation, but here's the code and it's not working, what can I do to make it work? I did these 3 functions that you ask for:

  • function that checks whether the arguments passed to the program are correct. This function returns 0 if the arguments are correct, otherwise it should return a value > 0, a value for every possible error;
  • function that prints error messages according to an error code passed to this function;
  • function that copies a file to the target file.
#include<stdio.h>
#include<stdlib.h>​
#define MAX 1000 // Atribuição para leitor char.​
#define MEN 500 // Atribuição para leitor char na função copiar arquivo​
​
void CopiaArq(FILE *arq1,FILE *arq2) // Função que cópia um arquivo e cola no outro.(2)​
int Arg(int n, char *v);// Função que retorna valoros maiores que 0 , quando há algum erro no programa.(1)​
char MensErro (char[MEN]);// Função que envia mnsagens de erro.(3)​
​
int​
main(int argc,char *argv)​
{​
    FILE *p==argv[2];// Nome do arquivo destino com atrubuição de valor no argv[2].​
    FILE *b==argv[4];// Nome do arquivo destino com atrubuição de valor no argv[4].​
​
    if(argc<5 || argc >5)​
    {​
        fprintf(stderr,"Erro de digitação no terminal\n");​
        return 1;​
    }​
    else​
    {​
​
    p=fopen("argv[2]","r"); // Abrindo arquivo no modo de leitura , somente para ver o seu conteúdo.​
    if(p==NULL)​
    {​
        fprintf(stderr,"Erro ao abrir o arquivo\n");​
        return 2;​
    }​
    b=fopen("argv[4]","w");// Abrindo o arquivo no modo escritra , possibilitando a copia dos arquivos.​
    if(b==NULL)​
    {​
        fprintf(stderr,"Erro ao abrir o arquivo\n");​
        return 3;​
    }​
    int Arg(argc, *argv); // Chamada da função(1).​
    char MensErro (char[500]); // Chamada da função(3).​
    void CopiaArq(p,b); // Chamada da função(2).​
    fclose(p); // Fechamento do arquivo p.​
    fclose(b);// Fechamento do arquivo b.​
    }​
  return 0;​
}​
​
void CopiaArq(FILE *arq1,FILE *arq2) // Função que coopia arquivos.​
{​
    char leitor[MAX];​
        while(fgets(leitor,MAX,arq1)!=NULL)​
        {​
            fputs(leitor,arq2);​
        }​
}​
​
​
int Arg(int n, char *v[])// funçãp que retorna valores maiores do que  zero se forem falsas e retorna 0 se for verdadeira.​
{​
    int n;​
    int i;​
    char v[4];​
​
    if(n!=5)​
    {​
        fprintf(stderr,"Erro de passagem nos argumentos para o terminal\n");​
        return 4;​
    }​
    for(i=0;i<4;i++)​
    {​
        fscanf(stdin,"%s",v[i]);​
        if (v[i]!=4)​
        {​
            fprintf(stderr,"Erro de passagem nos argumentos para o terminal\n");​
            return 5;​
        }​
        else​
        {​
            return 0;​
        }​
    }​
}​
char MensErro (char[MEN])// Função que mprime mensagem de erro.​
{​
    int i;​
    for(i=0;i<MEN;i++)​
    {​
        fprintf(stderr,"Codigo passado errado");​
    }​
    return MensErro;​
}​
​
    
asked by anonymous 19.09.2018 / 21:08

0 answers