#include "stdafx.h"
#include <iostream>
#include "stdio.h"
#include <io.h>
#include <fcntl.h>
#include <stdlib.h>
#include <share.h>

// Pete ze souboru nhodn sla, vypote jejich
// souet a vlo ho na konec souboru

int _tmain(int argc, _TCHAR* argv[])
{
	FILE *fh;
    int cislo,soucet;

	fopen_s(&fh,"data.dat", "r");

	soucet=0;

	do
	{
		fscanf_s(fh,"%d\n",&cislo);
		soucet+=cislo;
	}
	while (!feof(fh));

	fclose(fh);

	fopen_s(&fh,"data.dat", "a");
	fprintf(fh,"%d\n",soucet);
	fclose(fh);

	system("pause");

	return 0;
}
