Dear Sir/Madam,
I'm currently trying to compare a value from an array vs (In the first instance) A set character, and (in the second instance) against a set integer.
None of the comparisons are ever returning true even when they appear to be the same on a printf statement, although I would assume this is due to how I've stored such array and variables, and the way they're being outputted.
(Please note this should show the appropiate code listing, but some has been cropped as it's a lot that's not involved in this area)
char Input[3][100];
int ch;
=======================
do // Cycles through file and takes any item that's not a space or EoL and inputs to array (Used Integer due to needing it for testing EOF)
{
ch = fgetc(file);
printf("%c", ch);
if (ch == ' ')
{
Counter += 1;
}
else if (ch == '\n')
{
Counter = 0;
Counter2 += 1;
}
else
{
Input[Counter][Counter2] = ch;
}
} while (ch!=EOF);
fclose(file);
}
}
=============================
I'm trying to compare the value of each cell in the array as I believe the way I've done it it stores them as an ascii value, and as such I need to do:
if (Input[0][countinc] == 'A') //Compares array values and will return K to a value equal to input[0][0]-65
k = 0;
This code works fine, but is limiting me to having to repeat the code for every single ascii value, rather than being able to loop through just using a cast of the value to compare it to it's ascii value. For example if Input[0][0] = A or the ascii of A, k = ascii - X = 0, thus B = 1, C = 2 etc.
I have tried combinations of casting such as:
k = ((int)(Input[0][countinc])-64);
k = (int)k;
k = atoi(Input[0][countinc]);
None of these appear to work (and I have a feeling I just fail on casting :<)
Later in the program I'm trying to compare the same array values to an integer value for use in finding the smallest value in said array.
char CountMin[1];
CountMin[0] = "8";
for (y = 0; y <= (Vortex*Vortex); y++)
{
char k[1];
k[0] = Input[2][y];
printf("'%c'\n", k);
printf("'%c'\n", CountMin);
if (strcmp(k[0],CountMin[0])==0)
I've tried setting K as a string, and as an integer, and using this for a strncmp, strcmp, and simply a comparison of the two values using the above casts, Neither of which appear to work again.
====================================
I hope that wasn't too waffly to follow >.< and I apologise if I'm just being stupid here, Just none of the normal ways I'd do it appear to work, and the only reason I can assume is due to my taking "ch" in as Int for EOF, compared to take it in as char normally. Thus has the array saved my ch as the pure ascii values so when I take them out they show as something strange... But I don't know how to check.
Hope my waffling makes sense,
And thankies in advance.
Steph ^.^