Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <conio.h>
  4.  
  5. struct towar{
  6. int numer;
  7. double cena;
  8. int ilosc;
  9. char nazwa[30];
  10. };
  11.  
  12. void babcia(char * p);
  13.  
  14. int main(){
  15.  
  16. char plik[]="magazyn.txt";
  17. babcia(plik);
  18. return 0;
  19. }
  20.  
  21. void babcia(char *p){
  22. struct towar point;
  23. struct towar tempPoint;
  24. int numer,found;
  25. FILE * handle;
  26. FILE * tempHandle;
  27.  
  28. printf("Numer: ");
  29. fflush(stdin);
  30. scanf("%d", &point.numer);
  31.  
  32. printf("Cena: ");
  33. fflush(stdin);
  34. scanf("lf", &point.cena);
  35.  
  36. printf("Ilosc: ");
  37. fflush(stdin);
  38. scanf("%d", &point.ilosc);
  39.  
  40. printf("Nazwa: ");
  41. fflush(stdin);
  42. scanf("%s", point.nazwa);
  43.  
  44. numer=point.numer;
  45. found=point.ilosc;
  46.  
  47. if(handle=fopen(p,"r")){
  48. if(tempHandle=fopen("temp.txt","a+")){
  49. while(fread(&point, sizeof(struct towar), 1, handle)){
  50. if(point.numer==numer){
  51. point.ilosc+=found;
  52. fwrite(&point,sizeof(struct towar),1,tempHandle);
  53. }
  54. else
  55. fwrite(&point,sizeof(struct towar),1,tempHandle);
  56. }
  57.  
  58. }
  59. }
  60.  
  61. fclose(handle);
  62. fclose(tempHandle);
  63. remove(p);
  64. rename("temp.txt",p);
  65.  
  66.  
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement