The remove () and rename () functions do not work!

1
Hello, I'm doing a program in has a part of it that should delete a client and the data of such that they are in a .txt file! until that's fine, I create a new file with a different name that copies all the clients that were in the other file, minus the client to be deleted! but after doing this I need to delete the first file and change the name of the second to the first name!

Then I ran a search and found these two functions that promise to delete and rename files, it happens when trying to use them or erase or rename the files, I tried a lot of it, but nothing worked, even when I go to see output of the functions, instead of returning zero return -1. If anyone can help I would be very grateful!

Thank you in advance!

void copia_arquivo(FILE *file1, FILE *file2, char cpf[15])

{

char confirma_nome2[15];
char confirma_ultimoNome2[15];
char confirma_dataNasc2[11];
char confirma_cpf2[15];
int confirma_numero2;

 while (fscanf(file1, "%s %s  %s %i %s", confirma_nome2, confirma_ultimoNome2, confirma_dataNasc2, &confirma_numero2, confirma_cpf2) != EOF)
{
    if (strstr(cpf, confirma_cpf2) == 0)
    {
        fprintf(file2, "%s %s  %s %i %s\n", confirma_nome2, confirma_ultimoNome2, confirma_dataNasc2, confirma_numero2, confirma_cpf2);
    }
}
fclose(file1);
fclose(file2);
remove("clientes\client.txt");
rename("clientes\client2.txt", "clientes\client.txt");
}
    
asked by anonymous 14.06.2018 / 03:12

0 answers