Problems writing to .dat file using fputs on Mac

Before you ask, this is part of an assignment I have to do for class. That said, this is only a small portion of the assignment that I am having trouble with. This program is supposed to use structures and write flow rate tables for a civil engineering case study into .dat files. It is written in C using Codeblocks on a 2010 Macbook Pro, this does mean some minor edits in code sometimes. I will post the structure and the addfile function which is the one that writes to file.
Code for structure:
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
#define directory "/Users/everyone/Desktop/Assignment 3/" //This is needed beause fopen does not automatically go to the working directory on Mac.
#define extension ".FRT.dat" //The .FRT is in there because it was one of the assignment specifications, I tested it using a simpler write to file code using fputs and it worked fine.
#define NUMCOLS 10
#define NUMROWS 10
#define N_MAX 0.1
#define N_MIN 0.001

struct PARAM
{
    float s, z, n;
};
struct HEADING
{
    float initialValue, stepSize;
};
struct FLOW_RATE_TABLE
{
    char name[100];
    struct PARAM param;
    struct HEADING baseWidth;
    struct HEADING waterDepth;
    float flowRates[NUMCOLS][NUMROWS];
} flowRateTable;

void userInterface();
void addFlowRateTable();
bool setFlowRateTableName();
float readValueGTzero();
float computeFlowrate(float, float);
void loadFlowRateTable();
void displayFlowRateTable();
void estimateWaterDepth();
float getColIndex();
float getRowIndex();


Code for addfile:
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
FILE *pfile;
    int r, c;
    float temp, y, b;
    char string[10], filepath[100];
    if ((setFlowRateTableName())==true)
    {
        printf("Input the slope of the water: ");
        flowRateTable.param.s = readValueGTzero();
        printf("Input the slope of the channel sides: ");
        flowRateTable.param.z = readValueGTzero();
        do
        {
            printf("Please give the coefficient of roughness: ");
            scanf("%f", &temp);
            flowRateTable.param.n = temp;
            if (((flowRateTable.param.n)<N_MIN)||((flowRateTable.param.n)>N_MAX))
            {
                printf("The coefficient of roughness must be between %f and %f.\n", N_MIN, N_MAX);
            }
        }while (((flowRateTable.param.n)<N_MIN)||((flowRateTable.param.n)>N_MAX));
        printf("Input initial base width: ");
        flowRateTable.baseWidth.initialValue = readValueGTzero();
        printf("Input step size for base width: ");
        flowRateTable.baseWidth.stepSize = readValueGTzero();
        printf("Input inital water depth: ");
        flowRateTable.waterDepth.initialValue = readValueGTzero();
        printf("Input step size for water depth: ");
        flowRateTable.waterDepth.stepSize = readValueGTzero();
        y=flowRateTable.waterDepth.initialValue;
        for (r=0;r<NUMROWS;r++)
        {
            b = flowRateTable.baseWidth.initialValue;
            for (c=0;c<NUMCOLS;c++)
            {
                flowRateTable.flowRates[r][c] = computeFlowrate(b, y);
                b = b + flowRateTable.baseWidth.stepSize;
            }
            y = y + flowRateTable.waterDepth.stepSize;
        }
        strcpy(filepath, directory);
        strcat(filepath, flowRateTable.name);
        strcat(filepath, extension);
        pfile = fopen(filepath, "w");
        if (pfile != NULL)
        {
            printf("%s\n", filepath);
            fputs("           Base Depth-->\nWater Depth|", pfile);
            for (r=0;r<NUMROWS;r++)
            {
                temp = flowRateTable.baseWidth.initialValue + (r*flowRateTable.baseWidth.stepSize);
                sprintf(string, "%f", temp);
                fputs(string, pfile);
                fputs("\t", pfile);
            }
            for (r=0;r<NUMROWS;r++)
            {
                temp = flowRateTable.waterDepth.initialValue + (r*flowRateTable.waterDepth.stepSize);
                sprintf(string, "%4.2f", temp);
                fputs(string, pfile);
                fputs("|", pfile);
                for (c=0;c<NUMCOLS;c++)
                {
                    sprintf(string, "%4.2f", (flowRateTable.flowRates[r][c]));
                    //fwrite(string, 1, 6, pfile);
                    fputs(string, pfile);
                }
                fputs("\n", pfile);
            }
        } else {
            printf("Something is wrong with opening the file. At least you got this far?");//this will probably have to be changed to something more official.
        }
    }
    return;


It does make the file, but it comes out with nothing in it. I changed pfile to stdout to see if it would do anything and it printed off exactly what it was supposed to, but it won't go to the file. Can anyone tell me what is wrong here?
Topic archived. No new replies allowed.