#include <stdio.h>


int main(void)
{
	FILE *fpInput, *fpOutput;
	char name[20];
	int t1, t2, t3;
	int total;

	fpInput = fopen("calories.txt", "r");
	if (fpInput == NULL)
	{
		printf("File calories.txt does not exist.\n");
		return;
	}


	fpOutput = fopen("total_calories.txt", "w");
	if (fpOutput == NULL)
	{
		printf("Could not open output file.\n");
		return;
	}

	while(fscanf(fpInput, "%s %d %d %d", name, &t1, &t2, &t3) != EOF)
	{
		total = t1 + t2 + t3;
		fprintf(fpOutput, "%s\t%d\n", name, total);
	}

	fclose(fpInput);
	fclose(fpOutput);

	return 0;
}
