this works...if you tweak it a bit to read from a file, and write a function to remove spaces
the if condition is wear all the logic is checked....the outer loop just processes the whole string while the inner for loop processes each run of ANDs..
also you'll need to add support for things like a string consiting of only "T" or "F" (by itself)
Code:
#include <stdio.h>
int main()
{
char *p, test[]="F+T+F*F+T";
unsigned int flag = 0, res=1, lres=0;
p=test;
while (*p) {
for (;*p != '+' && *p;p++) { /* process and expressions */
if (*p == '*' && (*(p-1) == 'F' || *(p+1) == 'F') ||
(*p == 'F' && *(p-1) == '+' || *(p+1) == '+') ) {
if (flag)
res = lres || 0;
else
res = 0;
}
} /* end and processing loop */
if (*p == '+') {
flag = 1;
lres = res;
res = 1;
p++;
}
if (*p == '\0') {
printf("%s=%c\n",test,(res == 1 ? 'T' : 'F'));
break;
}
}
return 0;
}