I fail to see the logic in that program, but apart from that, it has many issues:
- You are checking the variables before you have placed any valid data inside them.
- Don't use global variables or goto unless motivated. It isn't motived in your program, it just mess things up and makes the code unreadable.
- void main() isn't ANSI C. Use int main().
- Use variable names that make sense. Not s, t, x, y, z.
Here is the working code based on your program:
#define MAX_STR_LEN 80
fp = fopen("data.txt","r");
if(fp == NULL)
printf("error message here");
printf("Enter string: ");
while(!feof(fp)) /* while not end of file */
fscanf(fp, "%s", candidate);
if(strcmp(key, candidate) == 0)
printf("Found \"%s\" %d times.\n", key, count);