Pagini recente » tema | tema | Cod sursa (job #499750) | Cod sursa (job #3296605) | Cod sursa (job #575184)
Cod sursa(job #575184)
#define _CRT_SECURE_NO_WARNINGS
#include <stdlib.h>
#include <stdio.h>
class File {
FILE * mhFile;
public:
File (const char * aFileName, const char * aOpenMode)
{
mhFile = fopen (aFileName, aOpenMode);
}
~File ()
{
if (IsOpen())
{
fclose (mhFile);
}
}
bool IsOpen () const { return NULL != mhFile; }
operator FILE * () const { return mhFile; }
};
int main(int argc, char * argv[])
{
File fIn ("adunare.in", "r");
if (!fIn.IsOpen()) return EXIT_FAILURE;
File fOut ("adunare.out", "w");
if (!fOut.IsOpen()) return EXIT_FAILURE;
long a, b;
int nRead = fscanf (fIn, "%ld\n%ld", &a, &b);
if (2 != nRead) return EXIT_FAILURE;
int nWritten = fprintf (fOut, "%ld", a + b);
if (1 != nWritten) return EXIT_FAILURE;
return EXIT_SUCCESS;
}