I have defined a function called checkrow, which reads a given element of a char array (fed to it by a pointer to char) and determines if it is equal to certain characters. When I compile my overall program, the compiler tells me that line 67, which is (if(*pInput == (' ' || '\t' || '\n')))
will never execute. Why? The logic makes sense to me. Below is the code.
#include <stdio.h>
#include <stdlib.h>
int checkRow(char *pArray);
int main (void){
char c = 0;
int high = 0;
int low = 9;
int checksum = 0;
char input[3000];
char *pInput = input;
FILE *pFile = NULL;
pFile = fopen("foo.txt", "r");
if (pFile == NULL){
printf("failed to open file\n");
return (-1);
}
while((c = fgetc(pFile)) != EOF){
*pInput = c;
++pInput;
}
fclose(pFile);
pFile = NULL;
pInput = input; //point pInput back to the address of the first element of input
//printf("the checksum is %d\n", checksum(pInput));
while(*pInput){
if(checkRow(pInput) == 0){
checksum += (high - low);
++pInput;
continue;
}
else{
if((*pInput - '0') > high && (*pInput - '0') < low){
high = *pInput - '0';
low = *pInput - '0';
++pInput;
continue;
}
else if (*pInput - '0' > high){
high = *pInput - '0';
++pInput;
continue;
}
else if(*pInput - '0' < low){
low = *pInput - '0';
++pInput;
}
}
}
printf("this is the checksum %d\n", checksum);
getchar();
return 0;
}
int checkRow(char *pInput){
int in = 0;
if(*pInput == (' ' || '\t' || '\n'))
in = 0;
else
in = 1;
return in;
}