Now that I think about it, you probably just need to move that (bonkers!) else part outside the loop and make it an if.
Code:
printf("Enter ID: ");
scanf("%s", &search_id);
FILE *fp = fopen("registration.txt", "r");
int cnt = 0;
while (fscanf(fp, "%s%s%s%s%s%s%s", &id, &name, &gender,
&coursename, &start_d, &end_d, &fee) != 7)
{
if (strcmp(id, id2) == 0)
{
printf("%s\n%s\n%s\n%s\n%s\n%s\n%s\n", name, id, gener,
coursename, start_d, end_d, fee);
++cnt;
}
}
if (cnt == 0)
{
printf("Error: id %s not found\n", id2);
}