String not printing data on next line despite \n in the string

Discussion in 'C Programming' started by SRK, Dec 24, 2009.

  1. SRK

    SRK Guest

    Hi folks,
    I am trying to read some data from a config file and want that data to
    be stored in a variable such that when I print it, it should print the
    string in a formatted way, for example if I have this string in the
    config file - ABC PQR XYZ in one line and want to display it like

    ABC
    PQR
    XYZ


    for that I have put the above mentioned string as ABC \nPQR \nXYZ.

    But instead of displaying the string in formatted way, when I print
    the data, it prints as ABC \nPQR \nXYZ. I am using FILE pointer for
    reading from the file and reading the line using fgets method.


    Any help would be highly appriciated.


    Thanks
    SRK
     
    SRK, Dec 24, 2009
    #1
    1. Advertising

  2. SRK

    Eric Sosman Guest

    On 12/24/2009 6:02 AM, SRK wrote:
    > Hi folks,
    > I am trying to read some data from a config file and want that data to
    > be stored in a variable such that when I print it, it should print the
    > string in a formatted way, for example if I have this string in the
    > config file - ABC PQR XYZ in one line and want to display it like
    >
    > ABC
    > PQR
    > XYZ
    >
    >
    > for that I have put the above mentioned string as ABC \nPQR \nXYZ.
    >
    > But instead of displaying the string in formatted way, when I print
    > the data, it prints as ABC \nPQR \nXYZ. I am using FILE pointer for
    > reading from the file and reading the line using fgets method.
    >
    >
    > Any help would be highly appriciated.


    Start with Question 8.8 in the comp.lang.c Frequently
    Asked Questions (FAQ) list at <http://www.c-faq.com/>. In
    brief, the C run-time I/O functions deliver characters "as
    is," which is a good deal less than what the C compiler does
    with source code.

    --
    Eric Sosman
    lid
     
    Eric Sosman, Dec 24, 2009
    #2
    1. Advertising

  3. On Thu, 24 Dec 2009 03:02:38 -0800 (PST), SRK <>
    wrote:

    >Hi folks,
    >I am trying to read some data from a config file and want that data to
    >be stored in a variable such that when I print it, it should print the
    >string in a formatted way, for example if I have this string in the
    >config file - ABC PQR XYZ in one line and want to display it like
    >
    >ABC
    >PQR
    >XYZ
    >
    >
    >for that I have put the above mentioned string as ABC \nPQR \nXYZ.
    >
    >But instead of displaying the string in formatted way, when I print
    >the data, it prints as ABC \nPQR \nXYZ. I am using FILE pointer for
    >reading from the file and reading the line using fgets method.
    >
    >
    >Any help would be highly appriciated.


    As the saying goes, "meet us halfway and buy a ticket". Do you really
    expect us to be able to diagnose the error in your code if you don't
    show us what you have done? Copy (using cut and paste, not retyping)
    you code as you compiled it into a reply message in this thread.

    --
    Remove del for email
     
    Barry Schwarz, Dec 24, 2009
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Neo Geshel
    Replies:
    2
    Views:
    1,102
    Neo Geshel
    Jun 14, 2005
  2. Deniz Bahar
    Replies:
    2
    Views:
    477
    Andrey Tarasevich
    Mar 9, 2005
  3. SRK
    Replies:
    13
    Views:
    604
    BGB / cr88192
    Jan 1, 2010
  4. Liora
    Replies:
    5
    Views:
    645
    Tad McClellan
    Jan 12, 2007
  5. Nene
    Replies:
    8
    Views:
    156
    -berlin.de
    Apr 20, 2007
Loading...

Share This Page