It took me a while to figure out what you're doing. I assume you don't expect a similar label somewhere down the list, so therefore we can just initialize the total once the label changes.
Code:
int main(int argc, char *argv[])
{
FILE *fin = fopen(argv[1],"r");
FILE *fout = fopen(argv[2],"w");
char t[15], t_d[15], c_d[16];
int tag, tag_d;
if (NULL == fin || NULL == fout) {
printf("Failure to open in or out files.\n");
return 0;
}
t[0] = '\0'; /* initialize to empty string */
while (fscanf(fin, "%s %s %d", t_d, c_d, &tag_d)==3) {
if (strcmp(t, t_d)) {
if (t[0])
fprintf(fout, "%s %s %d\n", t, c_d, tag);
tag = 0;
}
tag += tag_d;
strcpy(t, t_d);
}
fprintf(fout, "%s %s %d\n", t, c_d, tag);
fclose(fin);
fclose(fout);
return 0;
}
I realize that doing homework is against board policy, but the OP had most of it alright. Just needed a bit of clean-up and simplification.
And a real compile & run test to verify everything is OK.