Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static bool AlterarProduto(char idProduto, char nomeProduto[100], char tipoProduto[100], int qntProduto, float precoProduto) {
- /*
- * FAZER UMA STRING QUE SIMULA UMA LINDA DO BANCO DADOS
- * DEPOIS DE DESENVOLVER ESSA STRING EU VOU TER QUE INSERIR
- * ELA EM UM ARQUIVO COMO BACKUP E DEPOIS DELETAR O ARQUICO ORIGINAL
- * APÓS DELETAR O ARQUIVO ORIGINAL, EU DEVO POR CADA QUE ESTAVA NO
- */
- int numLinha = 0;
- char line[1024];
- char delimiter[] = ";";
- FILE* arquivo;
- FILE* newArquivo;
- char* palavras[50];
- int i = 0;
- char* values[9];
- char* fileLine[100];
- arquivo = AbreArquivo('l', tb_produto);
- while (fgets(line, sizeof line, arquivo) != NULL)
- {
- if (i == (idProduto - 49)) {
- snprintf(line, sizeof line, "%c;%s;%s;%d;%0.2f;\n", idProduto, nomeProduto, tipoProduto, qntProduto, precoProduto);
- fileLine[i] = _strdup(line);
- }
- else {
- fileLine[i] = _strdup(line);
- }
- i++;
- }
- FecharArquivo(arquivo);
- FILE* newFile = AbreArquivo('g', tb_produto2);
- if (newFile == NULL) {
- centerText(RED "\n\nOCORREU UM ERRO AO ALTERAR O PRODUTO", cmd_dimension.columns + 4);
- }
- else {
- for (int x = 0; x < i; x++) {
- fprintf(newFile, "%s", fileLine[x]);
- }
- }
- FecharArquivo(newFile);
- if (remove(tb_produto) == 0) {
- if (rename(tb_produto2, tb_produto) == 0) {
- return true;
- }
- }
- else {
- perror("remove");
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement