Having problem displaying a array of characters or symbols.

Hi, I am having an issue with my code, I have tried many solutions but just can't figure it out.

I have a array of floats, so decimal numbers, they are constant they don't change. I have to analyse the data in the table and if it is above, below or neither of its column and row average I assign it a symbol in a new array. Currently the numbers I use are -1,1,0. It prints fine and works the way I want it to. My issue arises when I want to change any of the numbers to symbols like... #$%^ or letters z,x,c,v etc. This is my code currently. If you can see what is wrong can you point me in the right direction.

Thank you

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
#define LessSymbol -1
#define MoreSymbol 1
#define NeitherSymbol 0
  

int averageMap[MAX_ROWS][MAX_COLS];
int MoreThanSymbol=MoreSymbol;
int LessThanSymbol=LessSymbol;
int NeitherThanSymbol=NeitherSymbol;


	for(row = 0; row < MAX_ROWS; row++){
		averageMap[row][col]=0;
		for(col = 0; col < MAX_COLS; col++){
			if ((rawData[row][col]>rowAverage[row]) && (rawData[row][col]>colAverage[col]))
				averageMap[row][col]=MoreThanSymbol;
			else if ((rawData[row][col]<rowAverage[row]) && (rawData[row][col]<colAverage[col]))
				averageMap[row][col]=LessThanSymbol;
			else if ((rawData[row][col]<rowAverage[row]) && (rawData[row][col]>colAverage[col])) 
				averageMap[row][col]=NeitherThanSymbol;
			else if ((rawData[row][col]>rowAverage[row]) && (rawData[row][col]<colAverage[col])) 
				averageMap[row][col]=NeitherThanSymbol;

		}
	}

	printf("Average Map\n");
	for(row = 0; row < MAX_ROWS; row++)
	{
		for(col = 0; col < MAX_COLS; col++)
		{
			printf("%d,", averageMap[row][col]);
		}
		printf("\n");
	}


This is just an extract from the code, But I am fairly sure the problem is in here.

Thank you very much, Any help is appreciated.
closed account (28poGNh0)
Can you put the whole code?
#include <stdio.h>
#include <stdlib.h>
/* Declare any constants */
/* Input file name */
#define FILE_NAME "data.csv"
/* Data size */
#define MAX_COLS 20
#define MAX_ROWS 20
#define DEBUG 1
#define LessSymbol -1
#define MoreSymbol 1
#define NeitherSymbol 0
#define MAX_CHAR 3

/*! Main entry point for the program

\return int
*/
int main (void)
{
/* Declare any variables */
/* Stores the data from input from the file */
float rawData[MAX_ROWS][MAX_COLS];
float rowAverage[MAX_ROWS];
float colAverage[MAX_COLS];
float rowSum[MAX_ROWS];
float colSum[MAX_COLS];
int averageMap[MAX_ROWS][MAX_COLS];
int row = 0;
int col = 0;
int MoreThanSymbol=MoreSymbol;
int LessThanSymbol=LessSymbol;
int NeitherThanSymbol=NeitherSymbol;
int rowCount[MAX_ROWS][MAX_CHAR];
int colCount[MAX_CHAR][MAX_COLS];


/* Misc vars */
float tempfloat = 0.0F;
float tmp = 0.0F;
char newline = ' ';

/* Open the file for reading */
FILE *infp;
infp = fopen(FILE_NAME,"r");

/* Check for errors and exit if found */
if(infp == NULL)
{
printf("Error: Failed to open %s for reading\n", FILE_NAME);
return(1);
}

/* Read the file into the data structure */
for(row = 0; row < MAX_ROWS ; row++)
{
/* Read up until the last value */
for(col = 0; col < MAX_COLS -1; col++)
{
if(fscanf(infp,"%f,", &tempfloat) != EOF)
rawData[row][col] = tempfloat;
else
{
printf("Error: incorrect file format at row %d, col %d.\n", row+1, col+1);
return(1);
}
}
/* Read the last value and the newline char */
if(fscanf(infp,"%f%c", &tempfloat, &newline) != EOF)
{
/* Check if the last character in the line was a \n otherwise an error occured. */
if(newline != '\n')
{
printf("Error: incorrect file format at line %d. did not find a newline.\n", row+1);
return(1);
}
else
rawData[row][col] = tempfloat;
/* Reset the character before the next read. */
newline = ' ';
}
}

/* Close the file */
fclose(infp);


if(DEBUG == 1)
{
/* Print the raw data read from the file */
printf("Raw Data\n");
for(row = 0; row < MAX_ROWS; row++)
{
for(col = 0; col < MAX_COLS; col++)
{
printf("%f,", rawData[row][col]);
}
printf("\n");
}

}

printf("Row Sum\n");

for(row = 0; row < MAX_ROWS; row++){
rowSum[row]=0;
for(col = 0; col < MAX_COLS; col++){
rowSum[row] +=rawData[row][col];
}
{
printf("%f",rowSum[row]);
}
printf("\n");
}

printf("Col Sum\n");

for(col = 0; col < MAX_COLS; col++){
colSum[col]=0;
for(row = 0; row < MAX_ROWS; row++){
colSum[col] +=rawData[row][col];
}
{
printf("%f",colSum[col]);
}
printf("\n");
}



printf("Row Average\n");

for(row = 0; row < MAX_ROWS; row++){
rowAverage[row]=0;
for(col = 0; col < MAX_COLS; col++){
rowAverage[row]=rowSum[row]/MAX_ROWS;


}
{
printf("%f",rowAverage[row]);
}
printf("\n");
}

printf("Col Average\n");

for(col = 0; col < MAX_COLS; col++){
colAverage[col]=0;
for(row = 0; row < MAX_ROWS; row++){
colAverage[col]=colSum[col]/MAX_COLS;
}
{
printf("%f",colAverage[col]);
}
printf("\n");
}

for(row = 0; row < MAX_ROWS; row++){
averageMap[row][col]=0;
for(col = 0; col < MAX_COLS; col++){
if ((rawData[row][col]>rowAverage[row]) && (rawData[row][col]>colAverage[col]))
averageMap[row][col]=MoreThanSymbol;
else if ((rawData[row][col]<rowAverage[row]) && (rawData[row][col]<colAverage[col]))
averageMap[row][col]=LessThanSymbol;
else if ((rawData[row][col]<rowAverage[row]) && (rawData[row][col]>colAverage[col]))
averageMap[row][col]=NeitherThanSymbol;
else if ((rawData[row][col]>rowAverage[row]) && (rawData[row][col]<colAverage[col]))
averageMap[row][col]=NeitherThanSymbol;

}
}

printf("Average Map\n");
for(row = 0; row < MAX_ROWS; row++)
{
for(col = 0; col < MAX_COLS; col++)
{
printf("%d,", averageMap[row][col]);
}
printf("\n");
}
printf("1's Sum\n");

for(row = 0; row < MAX_ROWS; row++){
rowCount[row][0]=0;
rowCount[row][1]=0;
rowCount[row][2]=0;
}
for(col = 0; col < MAX_COLS; col++){
colCount[0][col]=0;
colCount[1][col]=0;
colCount[2][col]=0;
}

for(row = 0; row < MAX_ROWS; row++){
for(col = 0; col < MAX_COLS; col++){
if (averageMap[row][col]==MoreSymbol)
rowCount[row][0]=rowCount[row][0]+1;
else if (averageMap[row][col]==NeitherSymbol)
rowCount[row][0]=rowCount[row][0]+1;
else if (averageMap[row][col]==LessSymbol)
rowCount[row][1]=rowCount[row][1]+1;
}
}

printf("Row Count\n");
for(row = 0; row < MAX_ROWS; row++)
{
for(col = 0; col < MAX_CHAR; col++)
{
printf("%d,", rowCount[row][col]);
}
printf("\n");
}

for(col = 0; col < MAX_COLS; col++){
for(row = 0; row < MAX_ROWS; row++){
if (averageMap[row][col]==MoreSymbol)
colCount[0][col]=colCount[0][col]+1;
else if (averageMap[row][col]==NeitherSymbol)
colCount[1][col]=colCount[1][col]+1;
else if (averageMap[row][col]==LessSymbol)
colCount[2][col]=colCount[2][col]+1;
}
}
printf("Col Count\n");
for(col = 0; col < MAX_COLS; col++){
for(row = 0; row < MAX_CHAR; row++){
printf("%d,", colCount[row][col]);
}
printf("\n");
}

/* End the program */
return 0;
}
I'm not sure I understand what the problem is. You have an array of ints, and you assign the ASCII values of chars to the array elements.

Can you tell us what you expected to happen and what actually happened?
And why do you need to assign symbols like "%"?
closed account (28poGNh0)
Your program really hypnotisms me ,also you're not helping well ,you did give me the code but worthless(for me) without the file data.csv so I erase some of your codes and I generated others

The first post (where you thought thats something wrong it) is perfectly fine ,a simple note is this segment
1
2
3
4
5
6
7
8
9
10
11
for(col = 0; col < MAX_COLS; col++)
{
    if ((rawData[row][col]>rowAverage[row]) && (rawData[row][col]>colAverage[col]))
        averageMap[row][col]=MoreThanSymbol;
    else if ((rawData[row][col]<rowAverage[row]) && (rawData[row][col]<colAverage[col]))
        averageMap[row][col]=LessThanSymbol;
    else if ((rawData[row][col]<rowAverage[row]) && (rawData[row][col]>colAverage[col])) 
        averageMap[row][col]=NeitherThanSymbol;
    else if ((rawData[row][col]>rowAverage[row]) && (rawData[row][col]<colAverage[col])) 
        averageMap[row][col]=NeitherThanSymbol;
}


has some radundant codes ,You need only to if's checks

1
2
3
4
5
if ((rawData[row][col]>rowAverage[row]) && (rawData[row][col]>colAverage[col]))
                averageMap[row][col]=MoreThanSymbol;
            else if ((rawData[row][col]<rowAverage[row]) && (rawData[row][col]<colAverage[col]))
                averageMap[row][col]=LessThanSymbol;
            else averageMap[row][col]=NeitherThanSymbol;


also you dont need averageMap[row][col]=0;

The problem I this is in this part
1
2
3
4
5
6
7
8
9
10
11
12
for(row = 0; row < MAX_ROWS; row++)
{
    for(col = 0; col < MAX_COLS; col++)
    {
        if (averageMap[row][col]==MoreSymbol)
            rowCount[row][0]=rowCount[row][0]+1;
        else if (averageMap[row][col]==NeitherSymbol)
            rowCount[row][0]=rowCount[row][0]+1;
        else if (averageMap[row][col]==LessSymbol)
            rowCount[row][1]=rowCount[row][1]+1;
    }
}


if you can notice there is no rowCount[row][2]

Otherwise your program is fine
this is closly the output I get

Raw Data
14.087.014.89.87.074.016.79.01.338.01.67.89.743.07.040.019.07.312.010.4
8.020.814.83.01.55.65.012.46.018.585.05.012.521.720.279.010.283.023.54.5
1.512.213.019.57.09.818.820.55.025.082.016.01.037.041.06.028.34.66.527.3
51.05.01.314.424.071.09.263.022.018.719.38.514.80.55.543.551.011.510.519.0
15.027.019.226.083.042.047.010.513.89.02.010.84.89.229.38.22.216.018.34.4
27.08.01.832.01.816.27.410.028.03.525.32.857.020.838.57.513.58.719.019.7
11.021.019.54.030.52.273.00.525.511.012.742.514.513.515.619.017.020.049.012.0
21.55.28.075.071.036.56.021.76.85.20.227.042.00.616.750.017.89.044.011.2
7.313.418.021.039.08.39.637.538.516.82.08.58.273.01.018.521.08.417.71.0
80.043.015.413.81.219.016.418.825.014.244.03.583.015.615.06.217.042.02.713.0
86.01.033.023.028.710.280.09.68.019.09.320.511.015.031.541.04.012.415.015.0
88.021.770.010.611.236.00.214.318.03.80.810.229.324.342.511.751.024.319.07.4
25.528.72.024.721.580.013.018.021.076.033.021.57.530.025.334.09.41.26.51.4
3.29.82.038.02.216.017.213.527.32.07.211.646.09.638.01.080.026.514.326.3
17.011.016.316.723.029.09.630.016.033.028.713.018.314.81.214.032.09.03.08.0
41.538.076.054.08.617.50.88.010.010.83.257.02.842.035.056.010.322.72.220.2
12.22.228.059.016.741.029.016.286.010.031.016.484.011.214.417.04.516.04.025.7
19.014.022.082.01.23.316.010.020.514.67.88.822.011.013.311.23.518.817.534.0
7.013.04.817.047.09.613.322.38.213.634.024.78.83.372.08.450.03.571.02.5
4.316.314.817.526.714.624.07.21.013.314.517.01.781.03.58.867.07.547.015.0
Row Sum
429.3
440.2
382.0
463.7
397.9
348.4
414.0
475.3
368.7
488.8
473.2
494.3
480.2
391.9
343.7
516.6
524.6
350.5
434.1
402.7
Col Sum
540.2
398.2
394.8
560.9
452.6
541.9
412.1
353.1
388.0
355.9
443.7
333.0
478.8
477.2
466.7
481.0
508.8
352.4
402.7
278.0
Row Average
21.5
22.0
19.1
23.2
19.9
17.4
20.7
23.8
18.4
24.4
23.7
24.7
24.0
19.6
17.2
25.8
26.2
17.5
21.7
20.1
Col Average
27.0
19.9
19.7
28.0
22.6
27.1
20.6
17.7
19.4
17.8
22.2
16.6
23.9
23.9
23.3
24.1
25.4
17.6
20.1
13.9
Average Map
-11-1-1-11-1-1-11-1-1-11-11-1-1-1-1
-10-1-1-1-1-1-1-101-1-1-1-11-111-1
-1-1-10-1-1-11-111-1-111-11-1-11
1-1-1-111-1100-1-1-1-1-111-1-10
-11-10111-1-1-1-1-1-1-11-1-1-1-1-1
0-1-11-1-1-1-11-11-1101-1-1-101
-11-1-11-11-11-1-11-1-1-1-1-101-1
-1-1-1111-10-1-1-111-1-11-1-11-1
-1-1-101-1-111-1-1-1-11-100-1-1-1
11-1-1-1-1-101-11-11-1-1-1-11-1-1
1-11-11-11-1-10-10-1-111-1-1-10
101-1-11-1-1-1-1-1-1101-110-1-1
01-10-11-100110-1111-1-1-1-1
-1-1-11-1-1-1-11-1-1-11-11-111-11
-1-1-1-111-11-111-10-1-1-11-1-1-1
1111-1-1-1-1-1-1-11-1111-10-10
-1-111-111-11-11-11-1-1-1-1-1-10
0-111-1-1-1-11-1-1-10-1-1-1-11-11
-1-1-1-11-1-11-1-111-1-11-11-11-1
-1-1-1-11-11-1-1-1-10-11-1-11-110
1's Sum
Row Count
501
412
712
676
523
666
667
745
456
634
676
678
756
701
667
8910
781
545
701
564
Col Count
5312
6212
5015
6410
9011
8012
5015
5312
7211
4313
8012
4313
6212
6212
9011
7112
7112
4313
5114
4511


The code is in the second post
closed account (28poGNh0)
Notice that I dont get from the file I just generate some nbrs
Hope that helps

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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
# include <stdio.h>
# include <stdlib.h>

#define FILE_NAME "data.csv"

#define MAX_COLS 20
#define MAX_ROWS 20
#define DEBUG 1
#define LessSymbol -1
#define MoreSymbol 1
#define NeitherSymbol 0
#define MAX_CHAR 3

int main (void)
{
    float rawData[MAX_ROWS][MAX_COLS];
    float rowAverage[MAX_ROWS],colAverage[MAX_COLS],rowSum[MAX_ROWS],colSum[MAX_COLS];
    int averageMap[MAX_ROWS][MAX_COLS];
    int row = 0,col = 0;
    int MoreThanSymbol = MoreSymbol,LessThanSymbol = LessSymbol,NeitherThanSymbol = NeitherSymbol;
    int rowCount[MAX_ROWS][MAX_CHAR],colCount[MAX_CHAR][MAX_COLS];

    for(int i=0;i<20;i++)
    {
        for(int j=0;j<20;j++)
            rawData[i][j] = (float)(rand()%88+1)/(rand()%5+1);
    }

    if(DEBUG == 1)
    {
        /* Print the raw data read from the file */
        printf("Raw Data\n");
        for(row = 0; row < MAX_ROWS; row++)
        {
            for(col = 0; col < MAX_COLS; col++)
                printf("%0.1f,", rawData[row][col]);
            printf("\n");
        }
    }

    printf("Row Sum\n");

    for(row = 0; row < MAX_ROWS; row++)
    {
        rowSum[row]=0;
        for(col = 0; col < MAX_COLS; col++)
            rowSum[row] +=rawData[row][col];

        printf("%f",rowSum[row]);
        printf("\n");
    }

    printf("Col Sum\n");

    for(col = 0; col < MAX_COLS; col++)
    {
        colSum[col]=0;
        for(row = 0; row < MAX_ROWS; row++)
            colSum[col] +=rawData[row][col];

        printf("%f",colSum[col]);
        printf("\n");
    }

    printf("Row Average\n");

    for(row = 0; row < MAX_ROWS; row++)
    {
        rowAverage[row]=0;
        for(col = 0; col < MAX_COLS; col++)
            rowAverage[row]=rowSum[row]/MAX_ROWS;

        printf("%f",rowAverage[row]);
        printf("\n");
    }

    printf("Col Average\n");

    for(col = 0; col < MAX_COLS; col++)
    {
        colAverage[col]=0;
        for(row = 0; row < MAX_ROWS; row++)
            colAverage[col]=colSum[col]/MAX_COLS;

        printf("%f",colAverage[col]);
        printf("\n");
    }

    for(row = 0; row < MAX_ROWS; row++)
    {
        for(col = 0; col < MAX_COLS; col++)
        {
            if ((rawData[row][col]>rowAverage[row]) && (rawData[row][col]>colAverage[col]))
                averageMap[row][col]=MoreThanSymbol;
            else if ((rawData[row][col]<rowAverage[row]) && (rawData[row][col]<colAverage[col]))
                averageMap[row][col]=LessThanSymbol;
            else averageMap[row][col]=NeitherThanSymbol;
        }
    }

    printf("Average Map\n");
    for(row = 0; row < MAX_ROWS; row++)
    {
        for(col = 0; col < MAX_COLS; col++)
            printf("%d,", averageMap[row][col]);

        printf("\n");
    }

    printf("1's Sum\n");

    for(row = 0; row < MAX_ROWS; row++)
    {
        rowCount[row][0]=0;
        rowCount[row][1]=0;
        rowCount[row][2]=0;
    }

    for(col = 0; col < MAX_COLS; col++)
    {
        colCount[0][col]=0;
        colCount[1][col]=0;
        colCount[2][col]=0;
    }

    for(row = 0; row < MAX_ROWS; row++)
    {
        for(col = 0; col < MAX_COLS; col++)
        {
            if (averageMap[row][col]==MoreSymbol)
                rowCount[row][0]=rowCount[row][0]+1;
            else if (averageMap[row][col]==NeitherSymbol)
                rowCount[row][1]=rowCount[row][0]+1;
            else if (averageMap[row][col]==LessSymbol)
                rowCount[row][2]=rowCount[row][1]+1;
        }
    }

    printf("Row Count\n");
    for(row = 0; row < MAX_ROWS; row++)
    {
        for(col = 0; col < MAX_CHAR; col++)
            printf("%d,", rowCount[row][col]);

        printf("\n");
    }

    for(col = 0; col < MAX_COLS; col++)
    {
        for(row = 0; row < MAX_ROWS; row++)
        {
            if (averageMap[row][col]==MoreSymbol)
                colCount[0][col]=colCount[0][col]+1;
            else if (averageMap[row][col]==NeitherSymbol)
                colCount[1][col]=colCount[1][col]+1;
            else if (averageMap[row][col]==LessSymbol)
                colCount[2][col]=colCount[2][col]+1;
        }
    }
    printf("Col Count\n");
    for(col = 0; col < MAX_COLS; col++)
    {
        for(row = 0; row < MAX_CHAR; row++)
            printf("%d,", colCount[row][col]);
        printf("\n");
    }

    /* End the program */
    return 0;
}
Last edited on
Sorry,

All of the code is fine, It works well and does what I need it to do. The only problem in the code is that I cannot change the 1,-1 and 0 to other symbols. That is all I need it to do. so I want to go to the #define LessSymbol -1 and change it to #define LessSymbol & and it will show a & symbol in the average map, instead of the -1. I realise currently the array is an int, it is because I don't know what it should be to allow me to do what I want. I tried char and that didn't work for me. Hope that is clearer.

Thank you
closed account (28poGNh0)
Well for that there a lots of methods

one way to do it ,is that you can check the value of averageMap[row][col] if it is -1 printf("&") that's easy

1
2
3
4
5
6
7
8
9
10
11
for(row = 0; row < MAX_ROWS; row++)
{
    for(col = 0; col < MAX_COLS; col++)
    {
        if(averageMap[row][col]==-1)
            printf("&,");
        else printf("%d,", averageMap[row][col]);
    }

    printf("\n");
}

Last edited on
I still want it to work like it is though, so I can count the occurrences of that symbol, letter or number. I have 3 different symbol,letter or numbers and I have a column and a row count to check how many there are. Is there a way to display the symbol, letter or number in the average map?

Thank you
closed account (28poGNh0)
Yes there is, did you not tried to replace the function I gave it to in the last post with the one in the first code ,replace it then you will get symboles and numbers

output :

Average Map
&,1,&,&,&,1,&,&,&,1,&,&,&,1,&,1,&,&,&,&,
&,0,&,&,&,&,&,&,&,0,1,&,&,&,&,1,&,1,1,&,
&,&,&,0,&,&,&,1,&,1,1,&,&,1,1,&,1,&,&,1,
1,&,&,&,1,1,&,1,0,0,&,&,&,&,&,1,1,&,&,0,
&,1,&,0,1,1,1,&,&,&,&,&,&,&,1,&,&,&,&,&,
0,&,&,1,&,&,&,&,1,&,1,&,1,0,1,&,&,&,0,1,
&,1,&,&,1,&,1,&,1,&,&,1,&,&,&,&,&,0,1,&,
&,&,&,1,1,1,&,0,&,&,&,1,1,&,&,1,&,&,1,&,
&,&,&,0,1,&,&,1,1,&,&,&,&,1,&,0,0,&,&,&,
1,1,&,&,&,&,&,0,1,&,1,&,1,&,&,&,&,1,&,&,
1,&,1,&,1,&,1,&,&,0,&,0,&,&,1,1,&,&,&,0,
1,0,1,&,&,1,&,&,&,&,&,&,1,0,1,&,1,0,&,&,
0,1,&,0,&,1,&,0,0,1,1,0,&,1,1,1,&,&,&,&,
&,&,&,1,&,&,&,&,1,&,&,&,1,&,1,&,1,1,&,1,
&,&,&,&,1,1,&,1,&,1,1,&,0,&,&,&,1,&,&,&,
1,1,1,1,&,&,&,&,&,&,&,1,&,1,1,1,&,0,&,0,
&,&,1,1,&,1,1,&,1,&,1,&,1,&,&,&,&,&,&,0,
0,&,1,1,&,&,&,&,1,&,&,&,0,&,&,&,&,1,&,1,
&,&,&,&,1,&,&,1,&,&,1,1,&,&,1,&,1,&,1,&,
&,&,&,&,1,&,1,&,&,&,&,0,&,1,&,&,1,&,1,0,


Is this what are you looking for
Yes, I tried it, I apologise for being a pain.

I need to be able to change it in one place to reflect it over the rest of the code, because there are other for loops relying on average map, If I use the printf("&,"); command, it wont reflect that in the column and row count.

That is why I tried to to define the symbol at the top, so I could go there. Change it and it would reflect that change in every for loop that was relying on the average map.

Thank you
closed account (28poGNh0)
I apologise for being a pain
dont said that ever ,for me that's fun :(

well In this case(I hope) You need to turn the type of averageMap from int to char

Okay
I initially tried that, and it still worked normally. But as soon as I changed the #define LessSymbol -1 to #define LessSymbol $, the problems started.

I changed the int LessThanSymbol=LessSymbol; to a
char LessThanSymbol=LessSymbol;

And the LessSymbol has a red error underline, it says Error identifier $ is undefined. Any ideas?

Thank you
Anyone have any idea?
printf("%c", (char)averageMap[row][col]);
printf("%c", (char)averageMap[row][col]);

That didn't work for me Daleth, I think the problem is where i define it. it says that it is undefined when i put anything but a number there
#include <stdio.h>
#include <stdlib.h>
/* Declare any constants */
/* Input file name */
#define FILE_NAME "data.csv"
/* Data size */
#define MAX_COLS 20
#define MAX_ROWS 20
#define DEBUG 1
#define LessSymbol g
#define MoreSymbol 1
#define NeitherSymbol 0
#define MAX_CHAR 3

/*! Main entry point for the program

\return int
*/
int main (void)
{
/* Declare any variables */
/* Stores the data from input from the file */
float rawData[MAX_ROWS][MAX_COLS];
float rowAverage[MAX_ROWS];
float colAverage[MAX_COLS];
float rowSum[MAX_ROWS];
float colSum[MAX_COLS];
char averageMap[MAX_ROWS][MAX_COLS];
int row = 0;
int col = 0;
char MoreThanSymbol=MoreSymbol;
char LessThanSymbol=LessSymbol;
char NeitherThanSymbol=NeitherSymbol;
int rowCount[MAX_ROWS][MAX_CHAR];
int colCount[MAX_CHAR][MAX_COLS];


/* Misc vars */
float tempfloat = 0.0F;
float tmp = 0.0F;
char newline = ' ';

/* Open the file for reading */
FILE *infp;
infp = fopen(FILE_NAME,"r");

/* Check for errors and exit if found */
if(infp == NULL)
{
printf("Error: Failed to open %s for reading\n", FILE_NAME);
return(1);
}

/* Read the file into the data structure */
for(row = 0; row < MAX_ROWS ; row++)
{
/* Read up until the last value */
for(col = 0; col < MAX_COLS -1; col++)
{
if(fscanf(infp,"%f,", &tempfloat) != EOF)
rawData[row][col] = tempfloat;
else
{
printf("Error: incorrect file format at row %d, col %d.\n", row+1, col+1);
return(1);
}
}
/* Read the last value and the newline char */
if(fscanf(infp,"%f%c", &tempfloat, &newline) != EOF)
{
/* Check if the last character in the line was a \n otherwise an error occured. */
if(newline != '\n')
{
printf("Error: incorrect file format at line %d. did not find a newline.\n", row+1);
return(1);
}
else
rawData[row][col] = tempfloat;
/* Reset the character before the next read. */
newline = ' ';
}
}

/* Close the file */
fclose(infp);


if(DEBUG == 1)
{
/* Print the raw data read from the file */
printf("Raw Data\n");
for(row = 0; row < MAX_ROWS; row++)
{
for(col = 0; col < MAX_COLS; col++)
{
printf("%f,", rawData[row][col]);
}
printf("\n");
}

}

printf("Row Sum\n");

for(row = 0; row < MAX_ROWS; row++){
rowSum[row]=0;
for(col = 0; col < MAX_COLS; col++){
rowSum[row] +=rawData[row][col];
}
{
printf("%f",rowSum[row]);
}
printf("\n");
}

printf("Col Sum\n");

for(col = 0; col < MAX_COLS; col++){
colSum[col]=0;
for(row = 0; row < MAX_ROWS; row++){
colSum[col] +=rawData[row][col];
}
{
printf("%f",colSum[col]);
}
printf("\n");
}



printf("Row Average\n");

for(row = 0; row < MAX_ROWS; row++){
rowAverage[row]=0;
for(col = 0; col < MAX_COLS; col++){
rowAverage[row]=rowSum[row]/MAX_ROWS;


}
{
printf("%f",rowAverage[row]);
}
printf("\n");
}

printf("Col Average\n");

for(col = 0; col < MAX_COLS; col++){
colAverage[col]=0;
for(row = 0; row < MAX_ROWS; row++){
colAverage[col]=colSum[col]/MAX_COLS;
}
{
printf("%f",colAverage[col]);
}
printf("\n");
}

for(row = 0; row < MAX_ROWS; row++){
averageMap[row][col]=0;
for(col = 0; col < MAX_COLS; col++){
if ((rawData[row][col]>rowAverage[row]) && (rawData[row][col]>colAverage[col]))
averageMap[row][col]=MoreThanSymbol;
else if ((rawData[row][col]<rowAverage[row]) && (rawData[row][col]<colAverage[col]))
averageMap[row][col]=LessThanSymbol;
else if ((rawData[row][col]<rowAverage[row]) && (rawData[row][col]>colAverage[col]))
averageMap[row][col]=NeitherThanSymbol;
else if ((rawData[row][col]>rowAverage[row]) && (rawData[row][col]<colAverage[col]))
averageMap[row][col]=NeitherThanSymbol;

}
}

printf("Average Map\n");
for(row = 0; row < MAX_ROWS; row++)
{
for(col = 0; col < MAX_COLS; col++)
{
printf("%c,", (char)averageMap[row][col]);
}
printf("\n");
}
printf("1's Sum\n");

for(row = 0; row < MAX_ROWS; row++){
rowCount[row][0]=0;
rowCount[row][1]=0;
rowCount[row][2]=0;
}
for(col = 0; col < MAX_COLS; col++){
colCount[0][col]=0;
colCount[1][col]=0;
colCount[2][col]=0;
}

for(row = 0; row < MAX_ROWS; row++){
for(col = 0; col < MAX_COLS; col++){
if (averageMap[row][col]==MoreSymbol)
rowCount[row][0]=rowCount[row][0]+1;
else if (averageMap[row][col]==NeitherSymbol)
rowCount[row][0]=rowCount[row][0]+1;
else if (averageMap[row][col]==LessSymbol)
rowCount[row][1]=rowCount[row][1]+1;
}
}

printf("Row Count\n");
for(row = 0; row < MAX_ROWS; row++)
{
for(col = 0; col < MAX_CHAR; col++)
{
printf("%d,", rowCount[row][col]);
}
printf("\n");
}

for(col = 0; col < MAX_COLS; col++){
for(row = 0; row < MAX_ROWS; row++){
if (averageMap[row][col]==MoreSymbol)
colCount[0][col]=colCount[0][col]+1;
else if (averageMap[row][col]==NeitherSymbol)
colCount[1][col]=colCount[1][col]+1;
else if (averageMap[row][col]==LessSymbol)
colCount[2][col]=colCount[2][col]+1;
}
}
printf("Col Count\n");
for(col = 0; col < MAX_COLS; col++){
for(row = 0; row < MAX_CHAR; row++){
printf("%d,", colCount[row][col]);
}
printf("\n");
}

/* End the program */
return 0;
}
Topic archived. No new replies allowed.