Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //adam foster
- //10/15/2019
- #include <stdio.h>
- #include <string.h>
- int main(void){
- FILE *ofPtr, *tfPtr, *nfPtr, *oPtr, *tPtr;
- ofPtr = fopen("oldmast.dat", "r");
- tfPtr = fopen("trans.dat", "r");
- nfPtr = fopen("newmast.dat", "w");
- oPtr = fopen("oldmast.dat", "r");
- tPtr = fopen("trans.dat", "r");
- int mastNum;
- int curNum;
- char name[25];
- char lname[25];
- float curBalance;
- float dollarAmount;
- int matchNum;
- float matchDollar;
- char matchName[25];
- char matchlName[25];
- int found = 0;
- while(fscanf(tfPtr, "%d %f\n", &curNum, &dollarAmount) == 2){ //looping through transactions
- //printf("%d %f\n", curNum, dollarAmount); //just displaying transaction info
- while(fscanf(ofPtr, "%d %s %s %f\n", &mastNum, &name, &lname, &curBalance) > 0){ //looping through old master
- //printf("%d\n", mastNum);
- if(mastNum == curNum){ //if the trans num == master num, we have found a match
- found = 1;
- matchNum = mastNum;
- matchDollar = curBalance;
- strcpy(matchName, name);
- strcpy(matchlName, lname);
- printf("Match found\n");
- //printf("Info: %d %s %s %.2f", matchNum, matchName, matchlName, matchDollar);
- }
- }
- if(found == 0) //if we never found a match, say something
- printf("Unmatched transaction record for account number: %d\n", curNum);
- if(found == 1){ //if we found a match, reset found to 0 for the next loop
- found = 0;
- //printf("%d\n", balance);
- fprintf(nfPtr, "%d %s %s %.2f\n", matchNum, matchName, matchlName, matchDollar + dollarAmount);
- }
- }
- found = 0; //resetting found
- 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
- printf("%d %s %s %f\n", mastNum, name, lname, curBalance);
- while(fscanf(tPtr, "%d %f\n", &curNum, &dollarAmount) > 0){
- printf("%d %d\n", mastNum, curNum);
- if(mastNum == curNum){
- //if the trans num == master num, we have found a match
- found = 1;
- printf("Match found\n");
- //printf("Info: %d %s %s %.2f", matchNum, matchName, matchlName, matchDollar);
- }
- }
- if(found == 0){
- printf("%d %s %s %.2f\n", mastNum, name, lname, curBalance);
- fprintf(nfPtr, "%d %s %s %.2f\n", mastNum, name, lname, curBalance);
- }
- if(found == 1){
- found = 0;
- }
- }
- fclose(ofPtr);
- fclose(tfPtr);
- fclose(nfPtr);
- fclose(oPtr);
- fclose(tPtr);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement