Hey All,
I have stumbled upon a small problem while using an fgets function. I need to make a program that reads in lines from a text file (text file is entered via command line)
Here is a little snippet of the code (concerning only the fgets function :P)
void loadText(list<char> &listId, char *file);
int main(int argc, char *argv[])
{
list<char> listId;
loadText(listId, argv[1]);
return 0;
}
void loadText(list<char> &listId, char *file)
{
ifstream fin;
fin.open(file);
char mystring[100];
while(fin >> mystring)
{
fgets (mystring, 100, file);
}
fin.close();
}
Now when I compile this I get an error:
"error cannot convert 'char*' to 'FILE*' for argument '3' to 'char* fgets(char*, int, FILE*)"
I try then to call fgets by the address of file i.e.
fgets (mystring, 100, &file);
Then I get the following error:
Now when I compile this I get an error:
"error cannot convert 'char**' to 'FILE*' for argument '3' to 'char* fgets(char*, int, FILE*)"
I have scoured the great interwebs for a similar problem and in one of the solutions the person called the &file and it worked but he did not have to use the command argument for a file (instead the file was inputed via cin)
Any thoughts?