I simply want to check whether a value which is present in a variable is integer or not.
My program below reads two values from "myfile.txt" and performs addition if and only if they are integers otherwise it returns "Invalid Output". I have successfully read values from "myfile.txt" but i have no way of checking whether the two values are integer or not.How to perform this test?
#include <stdio.h>
#include <conio.h>
int main()
{
FILE *fp;
int i, mkji, num, num1, num2;
int s = 0;
int a[2];
char term, term2;
clrscr();
fp = fopen("myfile.txt", "r+");
if (fp != 0)
{
for(i = 0; i < 2; i++)
{
fscanf(fp, "%d", &a[i]);
}
for(i = 0; i < 2; i++)
{
printf("%d\n", a[i]);
}
num = a[0];
num1 = a[1];
num2 = num + num1;
printf("%d", num2);
mkji = fclose(fp);
}
else
printf("FILE CANNOT BE OPEN");
getch();
return 0;
}