I have two different codes because i tried it 2 different ways i think. I have some examples with me and i just tried to follow thats how i did it, i know i probably did a mess but i tried it. I'm a beginner.
I still kind of lost and all help will appreciated.
1
Code:
#include <stdio.h>
main ()
{
int col1, col 2, col3, col4, col5,
file * infp , * outfp ;
infp = fopen("Columns Input.txt", "r"); /*Input of File .txt*/
outfp = fopen("Columns Output.txt", "w"); /*Output of File .txt*/
for (i=1; i<=count; i++)
fscanf (infp, "%d %d %d %d %d", &col1,&col2,&col3,&col4,&col5);
if((col1 < 5) && (col4 >= col5))
{
fprintf(outfp, "%d + %d = ", col1, col4, col1+col4);
fclose(infp);
fclose(outfp);
return 0;
}
2
Code:
#include<stdio.h>
#include<math.h>
int main(void)
{
FILE *infp, *outfp;
int col1, col2, col3, col4, col5, i, count;
if ((infp = fopen("input.txt", "r"))==NULL{
printf("input file cannot be opened\n");
return -1;
}
if ((outfp = fopen("output.txt", "w"))==NULL){
printf("output file cannot be opened\n");
return -1;
}
for (i=1; i<=count; i++)
fscanf (infp, "%d %d %d %d %d", &col1,&col2,&col3,&col4,&col5);
if((col1 < 5) && (col4 >= col5))
{
fprintf(outfp, "%d + %d = ", col1, col4, col1+col4);
fclose(infp);
fclose(outfp);
return 0;
}