I am having an issue with this piece of code. For some reason the 1st integer brought back is always 0.
The input file looks like this, which is stored in IP=6,51,64,50,29,21,37,35,34,63,48,42,8,13,52,46,1 7,9,54,25,61,26,28,45,15,43,44,18,49,20,32,10,40,3 1,30,57,56,60,4,12,53,47,5,22,58,27,38,23,3,11,19, 1,2,55,33,14,24,39,36,59,62,41,16,7
Code:
char *readChar[64];
int charCount = 0;
char *p;
int i, j;
int countArray[64] = {0};
lineBuffer = lineBuffer + 3;
for (p = strtok(lineBuffer, ","); p; p = strtok(NULL, ",")) {
if (charCount > 64) {
printError(3);
}
readChar[charCount++] = p;
}
if (charCount < 64) {
printError(3);
}
fprintf(stdout, "%i\n", atoi(readChar[0]));
for (i = 0; i < charCount; i++) {
countArray[atoi(readChar[i])]++;
}
for (i = 0; i < charCount; i++) {
fprintf(stdout, "%i occures %i\n", atoi(readChar[i]), countArray[i]);
}
for (i = 0; i < charCount; ++i) {
if (atoi(readChar[i]) > 64) {
printError(5);
}
for (j = i + 1; j < charCount; ++j) {
if (atoi(readChar[i]) == atoi(readChar[j])) {
printError(4);
}
}
}
For some reason, no matter what I get the following
Code:
0 occures 0
51 occures 1
64 occures 1
50 occures 1
29 occures 1
21 occures 1
37 occures 1
35 occures 1
34 occures 1
63 occures 1
48 occures 1
All of the other numbers seem to come through just fine. Can anyone help with this? I would greatly appreciate it. Thank you in advance!