Could someone please tell me what is wrong with this program. It is meant to return "GO" when
is in the input file, but it doesn't work.
Really annoying me. Need to know answer!!!!
char comet_name, group_name;
long int total1 = 1, total2 = 1;
int i, num = 0 ;
FILE *output, *input;
input = fopen("ride.in", "r");
output = fopen("ride.out", "w");
for(i = 0; comet_name[i] != NULL; i++)
num = comet_name[i];
total1 *= num;
for(i = 0; group_name[i] != NULL; i++)
num = group_name[i];
total2 *= num;
if ((total1%47) == (total2%47))
The Artful Lurker
I think you are trying to tackle this problem from the wrong angle. You say the program is meant to search for particular strings, yet what you are doing is multiplying the character values of the file contents and checking to see if it is evenly divisible by 47.
Once you have the contents of the file, you will need something to compare it too. You could either provide this in the code, or prompt the user for a value to search for. The ANSI C library functions strcmp() and strncmp() were made for this purpose. If this is a homework assignment that forbids the use of these ANSI functions, consider making a for loop that compares the elements of two character arrays.
Hope that helps,