Xcode vs PC file handling, specifically string compare

## Xcode vs PC file handling, specifically string compare

We started this code on a Mac and then finished on a PC. On the PC we used Visual Studio and on the Mac I used Xcode. The code compiles and runs on the PC ( or my Mac running Parallels ) with no problems. I can't get Xcode to run the whole program flawlessly. It will compile and run but the individual tasks don't complete properly. For instance, I can't search for a specific name in the file on my Mac but I can on a PC. I think it is in the string compare or how Xcode handles .txt files.

I am so close but I can't seem to get over this last little bump. I thought that the language would behave identically on different platforms. I guess not but now I don't know how they're different.

I have tried different IDE, moving the .txt file around, changing file paths, nothing seems to work.

Can anyone shed some light on this?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
void modifyRecord(){
    string lastName;
    char payrollTypeChar;
    double hoursWorkedDouble, payRateDouble;
    int unionCodeInt;
    cout << "Last name: ";
    while( !(cin >> lastName)){
            cout << "Error. please re-enter Last name: ";
            cin.clear();
            cin.ignore(10000,'\n');
    }
    const int SIZE = 100;
    // Number of items in the array.
    int count = 0;

    // Declare Array Variables for input by user
    string empLastName[SIZE];
    char   payrollType[SIZE];
    double hoursWorked[SIZE];
    double payRate[SIZE];
    int    unionCode[SIZE];

    //call getInput(...); with pointers that point to the original variables.
    getInput(empLastName, payrollType, hoursWorked, payRate, unionCode, count);
    for(int i = 0 ; i < count ; i ++){
        if(lastName.compare(empLastName[i]) == 0){
            payrollTypeChar = payrollType[i];
            hoursWorkedDouble = hoursWorked[i];
            payRateDouble = payRate[i];
            unionCodeInt = unionCode[i];
            char choice;
            //ask which fields need changes
            cout << "change payroll type(Y/N)? ";
            if(cin >> choice && (choice == 'y' || choice == 'Y')){
                cout << "Payroll type: ";
                while( !(cin >> payrollTypeChar)){
                        cout << "Error. please re-enter Payroll type: ";
                        cin.clear();
                        cin.ignore(10000,'\n');
                }
            }

            cout << "change hours worked(Y/N)? ";
            if(cin >> choice && (choice == 'y' || choice == 'Y')){
                cout << "Hours worked: ";
                while( !(cin >> hoursWorkedDouble)){
                        cout << "Error. please re-enter Hours worked: ";
                        cin.clear();
                        cin.ignore(10000,'\n');
                }
            }

            cout << "change pay rate(Y/N)? ";
            if(cin >> choice && (choice == 'y' || choice == 'Y')){
                cout << "Pay rate: ";
                while( !(cin >> payRateDouble)){
                        cout << "Error. please re-enter Pay rate: ";
                        cin.clear();
                        cin.ignore(10000,'\n');
                }
            }

            cout << "change Union code(Y/N)? ";
            if(cin >> choice && (choice == 'y' || choice == 'Y')){
                cout << "Union code: ";
                while( !(cin >> unionCodeInt)){
                        cout << "Error. please re-enter Union code: ";
                        cin.clear();
                        cin.ignore(10000,'\n');
                }
            }
            payrollType[i] = payrollTypeChar;
            hoursWorked[i]  = hoursWorkedDouble;
            payRate[i] = payRateDouble;
            unionCode[i] = unionCodeInt;
            //display the new record
            cout << "The new record: " << endl;
            cout << "Last Name: " << empLastName[i] << ", Payroll Type: " << payrollType[i] << ", hours worked: " << hoursWorked[i] << ", pay rate: " << payRate[i] << ", union code: " << unionCode[i] << endl;
            //write all to file
            writeFile(empLastName, payrollType, hoursWorked, payRate, unionCode, count);
            //sort
            BubbleSort(empLastName, payrollType, hoursWorked, payRate, unionCode, count);
            //display after sorting
            cout << "\n\nRecords after sorting: " << endl;
            for(int i = 0 ; i < count ; i ++)
                cout << "Last Name: " << empLastName[i] << ", Payroll Type: " << payrollType[i] << ", hours worked: " << hoursWorked[i] << ", pay rate: " << payRate[i] << ", union code: " << unionCode[i] << endl;
            return;
        }
    }
    cout << "No matching record" << endl;
    return;
}


I can't modify the record on the Mac
Last edited on
Are you using O/S specific file handling routines or the standard C library? Because the CRT standard library will handle files the same on every platform. But if you say are using Win32 and trying to compile on Mac with XCode, there is a potential (I'm not sure because I don't have much experience with XCode) that the Mac frameworks have that exact function but implemented differently. A good way to ensure the application behavior is the same across platforms is to use the C++ STL(Standard Template Library). It wraps a lot of the C functions with templates enabling them to function on any platform and also take any data type (within reason).

It would also be worth it to check and see if you MSVC install uses a different CRT version than your XCode install. Because some things are deprecated between libraries. It is also worth it to fix ALL warnings, regardless of how benign you think they may be and to also do printf() tracing through out your code to see what is being invoked and where.
Topic archived. No new replies allowed.