This looks like one of those relatively rare occasions when scanf() could be used.
You could try:
while (fscanf(fp, "%[^=]=%[^;]", name, value) == 2)
{
if ((c = fgetc(fp)) == EOF)
break;
else if (c == ';')
...continue with same line...
else if (c == '\n')
...wrap up current line...
else
...congratulations - format error of some sort...
}
Alternatively, continue to use 'fgets()' but use 'sscanf()' in a loop similar to this.
Working demo code:
#include <stdio.h>
int main(void)
{
char name[20];
char value[20];
while (fscanf(stdin, "%19[^=]=%19[^;]", name, value) == 2)
{
int c;
if ((c = fgetc(stdin)) == EOF)
break;
else if (c == ';')
printf("name = %s; value = %s\n", name, value);
else if (c == '\n')
printf("name = %s; value = %s\n", name, value);
else
fprintf(stderr, "Ooops!\n");
}
return(0);
}