Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <conio.h>
- struct towar{
- int numer;
- double cena;
- int ilosc;
- char nazwa[30];
- };
- void babcia(char * p);
- int main(){
- char plik[]="magazyn.txt";
- babcia(plik);
- return 0;
- }
- void babcia(char *p){
- struct towar point;
- struct towar tempPoint;
- int numer,found;
- FILE * handle;
- FILE * tempHandle;
- printf("Numer: ");
- fflush(stdin);
- scanf("%d", &point.numer);
- printf("Cena: ");
- fflush(stdin);
- scanf("lf", &point.cena);
- printf("Ilosc: ");
- fflush(stdin);
- scanf("%d", &point.ilosc);
- printf("Nazwa: ");
- fflush(stdin);
- scanf("%s", point.nazwa);
- numer=point.numer;
- found=point.ilosc;
- if(handle=fopen(p,"r")){
- if(tempHandle=fopen("temp.txt","a+")){
- while(fread(&point, sizeof(struct towar), 1, handle)){
- if(point.numer==numer){
- point.ilosc+=found;
- fwrite(&point,sizeof(struct towar),1,tempHandle);
- }
- else
- fwrite(&point,sizeof(struct towar),1,tempHandle);
- }
- }
- }
- fclose(handle);
- fclose(tempHandle);
- remove(p);
- rename("temp.txt",p);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement