Thread: Link list function call

  1. #16
    Registered User
    Join Date
    Mar 2008
    Posts
    43
    well with the fixed corrections im only getting one error at the return saying i cannot convert from an info_node* to int..
    Code:
    int build_list(struct info_node* pnode)
    {
    
    	FILE* infile ;
    	struct info_node* link1 ;
    	struct info_node* top ;
    	int result ;
    
    		infile = fopen("p3purge_data.txt", "r") ;
    
    		link1 = (info_node *)malloc(sizeof(info_node) ) ;
    		fscanf( infile, "%s%s%d%f", link1->fname , link1->lname, &link1->rank, &link1->score ) ;
    
    		top = link1 ;
    		
    		fclose(infile);
    	return(top) ;
    }

  2. #17
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    That is true. You can't. So don't.
    Code:
    struct info_node * build_list(struct info_node* pnode)

  3. #18
    Registered User
    Join Date
    Mar 2008
    Posts
    43
    so using that case how would i call the function

  4. #19
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    The same way... you would need casts for your current implementation. And casts be damned, your current implementation is just plain wrong.

  5. #20
    Registered User
    Join Date
    Mar 2008
    Posts
    43
    so the call would be something similiar to:
    Code:
    result = build_list(top)    ??


    Code:
    struct info_node * build_list(struct info_node* pnode)
    {
    
    	FILE* infile ;
    	
    	struct info_node* top;
    	int result = 0;
    
    		infile = fopen("p3purge_data.txt", "r") ;
    	
    		pnode = (info_node *)malloc(sizeof(info_node) ) ;
    		fscanf( infile, "%s%s%d%f", pnode->fname , pnode->lname, &pnode->rank, &pnode->score ) ;
    
    		top = pnode ;
    		fclose(infile);
    	return(top) ;
    }

  6. #21
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Why do you want result to be an int? Why would it ever be an int anyway? You want a pointer to an object not an integer. You could cast, but again, why?

  7. #22
    Registered User
    Join Date
    Mar 2008
    Posts
    43
    kk so i have it to build my list, quick question(if i do all the same things to build a separate list can i return two values under two different names(ie: return(top, top2)

  8. #23
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    You can call the function twice to build two different lists, yes. You can't return two different lists from the same function call.

  9. #24
    Registered User
    Join Date
    Mar 2008
    Posts
    43
    but i could pass the two different infiles in..got it. but say i wanted to use string compare to remove copied names out of one list that are in the other..is there any special approach to that or can i just use string compare in main somehow remove nodes that are copied?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 05-13-2011, 08:28 AM
  2. Need help with linked list sorting function
    By Jaggid1x in forum C Programming
    Replies: 6
    Last Post: 06-02-2009, 02:14 AM
  3. Sorting linked list please help with CODE
    By scarlet00014 in forum C Programming
    Replies: 3
    Last Post: 09-27-2008, 11:24 PM
  4. singly linked circular list
    By DarkDot in forum C++ Programming
    Replies: 0
    Last Post: 04-24-2007, 08:55 PM
  5. How can I traverse a huffman tree
    By carrja99 in forum C++ Programming
    Replies: 3
    Last Post: 04-28-2003, 05:46 PM