I am trying to design a program that would take input from a file(which consists of integers and words separated by a space and it would store the words in a linked list and print it in another function. My question is: How do I return the linked list struct to the main() for further process?
struct list* createlist(FILE *m);
struct list
{
char data[30];
struct list *next;
};
using namespace std;
main()
{
char a[100], ch;
cout<<"Enter the name of the file for obtaining input.."<<endl;
cin>>a;
FILE *in;
in=fopen(a,"r");
if(in!=NULL)
{
ch=fgetc(in);
if(ch=='1')
????=createlist(in);
fclose(in);
}
return 0;
}
struct list* createlist(FILE *m)
{
cout<<"Entered createlist function..!"<<endl;
char tempStr[30];
list *curr, *head;
char c;
int i=0;
curr=NULL;
while(EOF!=(c=fgetc(m)))
{
if((c==' ') || (c=='\0'))
{
if(i==0)
{
continue;
}
tempStr[i]='\0';
i=0;
continue;
}
tempStr[i]=c;
i++;
return ????
}
I dont know how to return so I marked it with question marks, the call part and the return part.