Thread: Getting weird characters in Strings

  1. #1
    steve8820
    Guest

    Question Getting weird characters in Strings

    I am currently having a problem with strings and pointers. I am reading in from a file to two different arrays.

    /*******
    example file:

    DEF CONE
    DEF STAR
    ********/

    The "DEF" goes into the first array and the "CONE" goes into the second array. When I test these out in main they print out correctly. But when I pass there reference to pointers in other functions I have problems with the first array. When I try a test print in another function, the pointer to the first array prints DEF then prints a few weird characters after it. They are extremely weird symbols. The strange thing is, when I do the same with other pointer to the second array it prints out fine in the other function. I am extremely puzzled to why this is happening. It anyone can help it would great.

  2. #2
    Anti-Terrorist
    Join Date
    Aug 2001
    Location
    mming, Game DevelopmentCSR >&<>&2Minimization of boolean functions, PROM,PLA design >&0>&WA, USA guitar, dogsCommercial Aviation >&>>&USAProgramming
    Posts
    742
    Post some code.
    I compile code with:
    Visual Studio.NET beta2

  3. #3
    Registered User
    Join Date
    Sep 2001
    Posts
    11

    Arrow I have the answer

    I know exactly what the problem is, had this one myself
    the other week.

    You aren't passing the strings appropriately,
    you need to change the function header (slightly).

    Email me and I'll send you code with the answer.

    [email protected]
    With my naked eye I saw all the falling rain, coming down on me...

  4. #4
    Registered User
    Join Date
    Sep 2001
    Posts
    2
    I think the first string was red by your program and your pointer
    has not allocated the proper memory for it, so printing the result
    (with your pointer) will print your string and a lot of mess behind it, because it don't know where to stop.
    The second will be succesfull, because and end of line is added
    behind the string and putted in memory where your second pointer points to ... so when printing it stops after the end of line character.

    You should allocate memory for your pointers !

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem with Strings, Please help!
    By varus in forum C++ Programming
    Replies: 8
    Last Post: 11-27-2006, 11:47 PM
  2. Programming using strings
    By jlu0418 in forum C++ Programming
    Replies: 5
    Last Post: 11-26-2006, 08:07 PM
  3. weird errors
    By R3N3G4D3 in forum Windows Programming
    Replies: 0
    Last Post: 06-14-2005, 06:54 AM
  4. menus and strings
    By garycastillo in forum C Programming
    Replies: 3
    Last Post: 04-29-2002, 11:23 AM
  5. Scanning characters & strings
    By rain_e in forum C Programming
    Replies: 2
    Last Post: 03-04-2002, 01:43 AM