Best way to load lines of text from a file to a combo box

This is a discussion on Best way to load lines of text from a file to a combo box within the Windows Programming forums, part of the Platform Specific Boards category; I use a while loop with the function fgets() but it adds the /n at the end and when it's ...

  1. #1
    Registered User
    Join Date
    Aug 2003
    Posts
    26

    Best way to load lines of text from a file to a combo box

    I use a while loop with the function fgets() but it adds the /n at the end and when it's in the combo box, the /n is a weird char.
    What do you think is the best way to do this.

  2. #2
    Even death may die... Dante Shamest's Avatar
    Join Date
    Apr 2003
    Location
    Malaysia
    Posts
    970
    Replace the newline character with a null character.

  3. #3
    Software Developer jverkoey's Avatar
    Join Date
    Feb 2003
    Location
    University of Waterloo
    Posts
    1,903
    in windows edit boxes, the newline character is actually read as: \r\n, so that should fix your problem

  4. #4
    Even death may die... Dante Shamest's Avatar
    Join Date
    Apr 2003
    Location
    Malaysia
    Posts
    970
    He's reading it in a combo box.

  5. #5
    Registered User
    Join Date
    Aug 2003
    Posts
    26
    Quote Originally Posted by Dante Shamest
    Replace the newline character with a null character.

    I can do this but I will have to use more lines of code, are there any shorter ways.

  6. #6
    Even death may die... Dante Shamest's Avatar
    Join Date
    Apr 2003
    Location
    Malaysia
    Posts
    970
    I can do this but I will have to use more lines of code, are there any shorter ways.
    You should only need a few more lines. For example, if line is the C-style string,

    Code:
    int iNewLine = strlen( line ) - 1 ;   // "\n" is stored at the end
    line[ iNewLine ]  = 0 ; // replace with 0

  7. #7
    Registered User
    Join Date
    Aug 2003
    Posts
    26
    Thanks Dante for doing the work for me, hehe. All I did was cut and paste your code and rename the variables and it works.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Newbie homework help
    By fossage in forum C Programming
    Replies: 3
    Last Post: 04-30-2009, 05:27 PM
  2. Totally confused on assigment using linked lists
    By Uchihanokonoha in forum C++ Programming
    Replies: 8
    Last Post: 01-05-2008, 04:49 PM
  3. Can we have vector of vector?
    By ketu1 in forum C++ Programming
    Replies: 24
    Last Post: 01-03-2008, 05:02 AM
  4. Basic text file encoder
    By Abda92 in forum C Programming
    Replies: 15
    Last Post: 05-22-2007, 02:19 PM
  5. how do I count the lines in a text file?
    By slow brain in forum C Programming
    Replies: 4
    Last Post: 03-10-2003, 02:56 PM

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