Thread: Transferring text from file into linked list

  1. #31
    Registered User
    Join Date
    Oct 2006
    Posts
    60
    right i've done that now and it has solved the problem, which gives me another one.

    The pointer stored in root->next is the memory address of the next word which I know is correct, although it seems to think the pointer is null. why would this happen?

    Edit: it seems it does test the words but then doesn't seem to call the function again, what I want it to do is test whether or not the word entered by the user is in the list and how many times it occurs.

    Edit: Edit: it searches through the list now but seems to get a pointer error on the last node I think.
    Last edited by manutdfan; 01-18-2007 at 09:43 AM.

  2. #32
    Registered User
    Join Date
    Oct 2006
    Posts
    60
    duh of course I get a pointer error as it is the start of the list, anyway it now seems to work although b should be the number of times a word occurs in the list and it doesn't always seem to be.

    Also is it possible to return both a and b from the same function?

  3. #33
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    you can pass them by pointer
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  4. #34
    Registered User
    Join Date
    Oct 2006
    Posts
    60
    thanks, I realised I only needed to transfer them back to print out so I have just incorporated the printf statements into the search function.

    Just wondering is it possible to condense the printf commands below anymore:
    Code:
            printf("\n'%s'", word);
            printf(" occurs ");
            printf("%d", b);
            printf(" times.\nRetrieval from list took");
            printf("%d",a);
            printf(" comparisons. ");

  5. #35
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    printf("\n'%s' occurs %d times.\nRetrieval from list took %d comparisons.", word,b,a);
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  6. #36
    Registered User
    Join Date
    Oct 2006
    Posts
    60
    I want to remove apostrophes from my text, but if I use the following statement it thinks there are too many as they are the initialiser for the query. How would I get round this? I was wondering whether it is possible to use ASCII code.

    x[b] == '''

    thanks

  7. #37
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    you can use \" to print quote instead of the '
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  8. #38
    Registered User
    Join Date
    Oct 2006
    Posts
    60
    so i should use

    x[b] == '\"'

    because it doesn't seem to work.

  9. #39
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    i mean you can write
    Code:
    printf("\n\"%s\" occurs %d times.\nRetrieval from list took %d comparisons.", word,b,a);
    if you want to do something else - please explain a little bit more
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  10. #40
    Registered User
    Join Date
    Oct 2006
    Posts
    60
    no sorry I am trying to remove all the apostrophes from my list so when it is searched they don't appear in words.

    so I was trying to compare each character in the list with an apostrophe to allow me to find and remove them.

    my attempt was x[b] == '''

    with the highlighted bit being the condition.

  11. #41
    {Jaxom,Imriel,Liam}'s Dad Kennedy's Avatar
    Join Date
    Aug 2006
    Location
    Alabama
    Posts
    1,065
    You'd need an escape char with that. . . '\'' where the \ means the next char, if not a special char is litteral.

  12. #42
    Registered User
    Join Date
    Oct 2006
    Posts
    60
    thanks, thats great it works now

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. help! Placement of nodes in a Linked List
    By lostmyshadow in forum C Programming
    Replies: 6
    Last Post: 12-17-2007, 01:21 PM
  2. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  3. struct question
    By caduardo21 in forum Windows Programming
    Replies: 5
    Last Post: 01-31-2005, 04:49 PM
  4. How can I traverse a huffman tree
    By carrja99 in forum C++ Programming
    Replies: 3
    Last Post: 04-28-2003, 05:46 PM
  5. Outputting String arrays in windows
    By Xterria in forum Game Programming
    Replies: 11
    Last Post: 11-13-2001, 07:35 PM