this code is ment to get 4 variables from an input file and then to take those 4 variable and add +1 to other variable(havnt added yet) but when I tested in values taken it came with some good answers but also a ton of bad values that I dont know how to fix.
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <math.h>
#include <string.h>
int main(void)
{
int counter = 0;
FILE* infile = fopen("input.txt", "r");// input file with 4 variabels.
typedef struct person// struct for 4 variables
{
char gender;
char gamer;
char toxic;
int age;
}person;
person people[50];
while (!feof(infile))// continue until end of file
{
fscanf(infile, "%c", &people[counter].gender);//grabs letter for gender (M/F)
fscanf(infile, "%c", &people[counter].gamer);// grabs letter for gamer (Y/N)
fscanf(infile, "%c", &people[counter].toxic);// grabs letter for toxic (Y/N)
fscanf(infile, "%d", &people[counter].age);// grabs int for age (#)
printf("%c\n%c\n%c\n%d\n", people[counter].gender, people[counter].gamer, people[counter].toxic, people[counter].age);// was checking for if the variable were getting correct inputs
++counter;// Updates counter for next person
}
}
It keeps returning some values but also some weird values.