Thread: Using a linked list globally and File I/O

  1. #46
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    You are using break/continue in a non-traditional way, and I don't think you actually mean to do it that way, as there is so little benefit and huge increase in confusion from it [in fact, I think most of your confusion stems from this].

    Change ALL of your continue to break.

    Then use do - while instead of for(;, and set a flag based on your choice2 input.

    However, you also compare choice2 with the string "y" - this will not work - choice2's location in memory will never ever match the string "y" [at least not and also function correctly with the fgets() that you are using]. You need to use strcmp or just use a compare of the first character of your string.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  2. #47
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Code:
    if (choice2=="y") break;
    OK, so choice is char* and "y" is char*, so you're basically comparing pointer vs. pointer, and that's why it doesn't work.
    If you need to compare a char against a char, you would do choice[n] = 'n' as you did. If you need to compare a string against another string, you need to use strcmp.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. linked list versus array
    By FoodDude in forum C++ Programming
    Replies: 18
    Last Post: 08-22-2005, 10:57 AM