Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.45 KB | None | 0 0
  1. //adam foster
  2. //10/15/2019
  3. #include <stdio.h>
  4. #include <string.h>
  5. int main(void){
  6.   FILE *ofPtr, *tfPtr, *nfPtr, *oPtr, *tPtr;
  7.   ofPtr = fopen("oldmast.dat", "r");
  8.   tfPtr = fopen("trans.dat", "r");
  9.   nfPtr = fopen("newmast.dat", "w");
  10.  
  11.   oPtr = fopen("oldmast.dat", "r");
  12.   tPtr = fopen("trans.dat", "r");
  13.   int mastNum;
  14.   int curNum;
  15.   char name[25];
  16.   char lname[25];
  17.   float curBalance;
  18.   float dollarAmount;
  19.   int matchNum;
  20.   float matchDollar;
  21.   char matchName[25];
  22.   char matchlName[25];
  23.   int found = 0;
  24.   while(fscanf(tfPtr, "%d %f\n", &curNum, &dollarAmount) == 2){ //looping through transactions
  25.     //printf("%d %f\n", curNum, dollarAmount); //just displaying transaction info
  26.     while(fscanf(ofPtr, "%d %s %s %f\n", &mastNum, &name, &lname, &curBalance) > 0){ //looping through old master
  27.       //printf("%d\n", mastNum);
  28.       if(mastNum == curNum){ //if the trans num == master num, we have found a match
  29.     found = 1;
  30.     matchNum = mastNum;
  31.     matchDollar = curBalance;
  32.     strcpy(matchName, name);
  33.     strcpy(matchlName, lname);
  34.     printf("Match found\n");
  35.     //printf("Info: %d %s %s %.2f", matchNum, matchName, matchlName, matchDollar);
  36.       }
  37.     }
  38.     if(found == 0) //if we never found a match, say something
  39.       printf("Unmatched transaction record for account number: %d\n", curNum);
  40.     if(found == 1){ //if we found a match, reset found to 0 for the next loop
  41.       found = 0;
  42.       //printf("%d\n", balance);
  43.       fprintf(nfPtr, "%d %s %s %.2f\n", matchNum, matchName, matchlName, matchDollar + dollarAmount);
  44.     }
  45.   }
  46.   found = 0; //resetting found
  47.   while(fscanf(oPtr, "%d %s %s %f\n", &mastNum, &name, &lname, &curBalance) > 0){ //now we are comparing the old mast to all the trans, as opposed to before
  48.     printf("%d %s %s %f\n", mastNum, name, lname, curBalance);
  49.     while(fscanf(tPtr, "%d %f\n", &curNum, &dollarAmount) > 0){
  50.       printf("%d %d\n", mastNum, curNum);
  51.       if(mastNum == curNum){
  52.       //if the trans num == master num, we have found a match
  53.       found = 1;
  54.       printf("Match found\n");
  55.       //printf("Info: %d %s %s %.2f", matchNum, matchName, matchlName, matchDollar);
  56.       }
  57.     }
  58.     if(found == 0){
  59.       printf("%d %s %s %.2f\n", mastNum, name, lname, curBalance);
  60.       fprintf(nfPtr, "%d %s %s %.2f\n", mastNum, name, lname, curBalance);
  61.     }
  62.     if(found == 1){
  63.       found = 0;
  64.     }
  65.   }
  66.        
  67.      
  68.  
  69.   fclose(ofPtr);
  70.   fclose(tfPtr);
  71.   fclose(nfPtr);
  72.   fclose(oPtr);
  73.   fclose(tPtr);
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement