I apologize if this question is obvious, or if I make a simple logical mistake. I have been looking for various ways to get rid of the new line that comes from using fgets, but I continue to run into problems when building. I think that I do not understand something correctly and incorrectly apply my "solution". I would like to be transparent and say that this is a school assignment. Everything works well, except for my output, which has unnecessary newlines.
The sole purpose of this function is to read names into an array of structures.
void initialize(FILE * ifp, Candidate * electionCandidates, int count)
{
for (int i = 0; i < count; i++)
{
fgets (electionCandidates[i].name , 20 , ifp);
if (electionCandidates[i].name[strlen(electionCandidates[i].name) - 1] == '\n')
{
electionCandidates[i].name[strlen(electionCandidates[i].name) - 1] = '\0';
}
}
}
When trying to do the following: "Implicitly declares a library function" strlen "of type unsigned long (constant char *)"