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

S

SRK

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
 
E

Eric Sosman

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.
 
B

Barry Schwarz

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,019
Latest member
RoxannaSta

Latest Threads

Top