complete the gaps

This is a discussion on complete the gaps within the C Programming forums, part of the General Programming Boards category; the function is supposed to construct a linked list out of the inputed word i completed as far as i ...

  1. #1
    Banned
    Join Date
    Oct 2008
    Posts
    1,535

    complete the gaps

    the function is supposed to construct a linked list out of
    the inputed word

    i completed as far as i could.

    why i need temp and temp2
    ??
    Code:
    #include <stdio.h>	
    #include <stdlib.h>
    #include <string.h>
    
    typedef struct wordStruct{
    	char string[256];
    	struct wordStruct *next;
    } wordStruct;
    
    wordStruct * wordAlloc(char *str){
    	wordStruct *temp;
    	temp = (wordStruct *)malloc(sizeof(wordStruct));
    	temp->next=NULL;
    	strcpy(temp->string,str);
    	return temp;
    } 
    
    wordStruct *insert( wordStruct *head, char *st){
    	wordStruct* temp, *temp2;
    	
    	if(head == NULL) return wordAlloc(st);
    	
    	if(?? 6 ??|| (?? 7 ?? && ?? 8 ??)){
    		temp = ?? 9 ??;
    		?? 10 ??;
    		return temp;
    	}
    	
    	for(temp=head; temp->next ; temp = temp -> next){
    		if(?? 11 ??)break;
    		if( ?? 12 ??&& ?? 13 ??)break;
    	}	
    	
    	temp2 = temp->next;
    	?? 14 ??;
    	?? 15 ??;
    	return head;	
    }
    
    void main(){	
    	char word[256];
    	wordStruct *list = NULL;
    	
    	while(scanf("%s", word)==1)
    		list = insert(list, word);				
    	. . . .	
    }

  2. #2
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    Looks to me like temp and temp2 are just pointers used for traversing the list, almost like cursors. This certainly looks like an assessment, so please don't look for more specific help...

  3. #3
    Registered User
    Join Date
    Oct 2008
    Location
    TX
    Posts
    2,047
    Usually temp variables are used for swapping / re-organizing elements of a linked list.
    However you will get a better answer if those question marks were replaced by real code.

  4. #4
    Banned
    Join Date
    Oct 2008
    Posts
    1,535
    the whole question is about replacing them

  5. #5
    Banned
    Join Date
    Oct 2008
    Posts
    1,535
    how to traverse the list
    ??

  6. #6
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,659
    >> void main()

    Why is it that you refuse to return an int from main? I've already pointed this out to you no less than three times this week, and I'm sure many others have done as well before. It is an *error*. Period.

    >> i completed as far as i could.

    Well, if you would actually read and then try to understand responses to some of your previous questions, you might make some progress.



    ITSA
    Socket Library!

  7. #7
    Registered User
    Join Date
    Oct 2008
    Location
    TX
    Posts
    2,047
    Quote Originally Posted by transgalactic2 View Post
    the whole question is about replacing them
    Are you supposed to fill in those blanks ie question marks with code? What are those numbers for then?

  8. #8
    Banned
    Join Date
    Oct 2008
    Posts
    1,535
    Quote Originally Posted by itCbitC View Post
    Are you supposed to fill in those blanks ie question marks with code? What are those numbers for then?
    yes.
    we have a paper and we
    say
    ??1?? : bla bla
    ??2?? : hhfff

    etc..

    and we get a grade if we substitute the correct code

  9. #9
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Quote Originally Posted by transgalactic2 View Post
    and we get a grade if we substitute the correct code
    I'm betting you get a lousy grade.


    Quzah.
    Hope is the first step on the road to disappointment.

  10. #10
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,659
    >> and we get a grade if we substitute the correct code

    I'm pretty sure the "we" is referring to *you*, and not *us*.



    ITSA
    Socket Library!

  11. #11
    Banned
    Join Date
    Oct 2008
    Posts
    1,535
    yes

    so how to use temp and temp 2

    if null then it returns the node of the given string

    if not then
    i would use temp to go to the end of the list and then say
    temp->next=wordalloc(st);
    return head;

    thats it

    i dont know why they write so many lines there
    ?

  12. #12
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Why don't you just try writing your own from scratch? Once you have that working, see how your version is different than their version.


    Quzah.
    Hope is the first step on the road to disappointment.

  13. #13
    Banned
    Join Date
    Oct 2008
    Posts
    1,535
    i already showed you my solution

    and it differs allot
    by the number of lines
    and the type of them


    for example you see that i dont use "if' at all

    and it works fine

    so how to think of a solution that they are after at
    Last edited by transgalactic2; 07-01-2009 at 03:33 PM.

  14. #14
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Quote Originally Posted by transgalactic2 View Post
    i already showed you my solution
    No you didn't. You didn't post anything other than that first post of "Here's some code I was given, I'm supposed to fill in the blanks. Can you do it for me?"


    Quzah.
    Hope is the first step on the road to disappointment.

  15. #15
    Banned
    Join Date
    Oct 2008
    Posts
    1,535
    i forgot that its supposed to be sorted by length
    and if two words have equal length then by dictionary order

    so my solution is no good

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. First phases complete for space combat
    By VirtualAce in forum Game Programming
    Replies: 5
    Last Post: 01-22-2009, 08:42 AM
  2. binary tree complete check
    By ichijoji in forum C++ Programming
    Replies: 5
    Last Post: 11-12-2004, 04:48 PM
  3. Replies: 14
    Last Post: 04-27-2003, 06:37 PM
  4. Doom Lord engine complete!
    By Leeman_s in forum Game Programming
    Replies: 8
    Last Post: 05-12-2002, 12:44 AM
  5. doom lord engine complete!
    By Leeman_s in forum C++ Programming
    Replies: 4
    Last Post: 04-25-2002, 08:41 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21