Advertisement
Guest User

Untitled

a guest
Dec 5th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. static bool AlterarProduto(char idProduto, char nomeProduto[100], char tipoProduto[100], int qntProduto, float precoProduto) {
  2. /*
  3. * FAZER UMA STRING QUE SIMULA UMA LINDA DO BANCO DADOS
  4. * DEPOIS DE DESENVOLVER ESSA STRING EU VOU TER QUE INSERIR
  5. * ELA EM UM ARQUIVO COMO BACKUP E DEPOIS DELETAR O ARQUICO ORIGINAL
  6. * APÓS DELETAR O ARQUIVO ORIGINAL, EU DEVO POR CADA QUE ESTAVA NO
  7. */
  8.  
  9. int numLinha = 0;
  10. char line[1024];
  11. char delimiter[] = ";";
  12. FILE* arquivo;
  13. FILE* newArquivo;
  14. char* palavras[50];
  15. int i = 0;
  16. char* values[9];
  17. char* fileLine[100];
  18. arquivo = AbreArquivo('l', tb_produto);
  19.  
  20. while (fgets(line, sizeof line, arquivo) != NULL)
  21. {
  22. if (i == (idProduto - 49)) {
  23. snprintf(line, sizeof line, "%c;%s;%s;%d;%0.2f;\n", idProduto, nomeProduto, tipoProduto, qntProduto, precoProduto);
  24. fileLine[i] = _strdup(line);
  25. }
  26. else {
  27. fileLine[i] = _strdup(line);
  28. }
  29. i++;
  30. }
  31.  
  32. FecharArquivo(arquivo);
  33.  
  34. FILE* newFile = AbreArquivo('g', tb_produto2);
  35. if (newFile == NULL) {
  36. centerText(RED "\n\nOCORREU UM ERRO AO ALTERAR O PRODUTO", cmd_dimension.columns + 4);
  37. }
  38. else {
  39. for (int x = 0; x < i; x++) {
  40. fprintf(newFile, "%s", fileLine[x]);
  41. }
  42. }
  43. FecharArquivo(newFile);
  44.  
  45. if (remove(tb_produto) == 0) {
  46. if (rename(tb_produto2, tb_produto) == 0) {
  47. return true;
  48. }
  49. }
  50. else {
  51. perror("remove");
  52. return false;
  53. }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement