Returning structure reference in a C function [message #759319] |
Mon, 28 November 2011 11:19 |
Shashank Messages: 6 Registered: January 2011 |
Junior Member |
|
|
Hello,
I was wondering if someone could let me know if there are any issues with the CDT and returning structure references.
I have the below code for reading file content into a linked list:
struct list_node
{
char dir[BUFSIZ];
struct list_node *next;
};
typedef struct list_node list;
int main( )
{
parse_file();
}
//list is structure
/*Error line*/ list * parse_file()
{
const char filename[] = "find_inotify.txt";
FILE *file = fopen(filename, "r");
list *curr;
list *head;
char * errorcode = NULL;
head = NULL;
if ( file )
{
char line [ BUFSIZ ];
while ( fgets(line, sizeof line, file) )
{
curr = (list *)malloc(sizeof(list));
strcpy(curr->dir, line);
curr->next = head;
head = curr;
}
while(head) {
printf("%s\n", curr->dir);
head = head->next ;
}
}
else
{
perror(filename);
}
}
return head;
}
Everything works fine except for the function return type. Changing the return type to int and returning a random integer fixes this. I am looking for a way for this function to return the linked list.
Thanks.
Eclipse build error at /*Error line*/ : conflicting types for 'parse_file'
OS : Ubuntu 11.10
Eclipse Version: 3.7.0
[Updated on: Mon, 28 November 2011 11:19] Report message to a moderator
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03013 seconds