hi .

i have read a line from a text file & stored it in a string using fgets().

the file contains the following line:
C:\Windows\

char myline[20];
fgets(myline,20,fp);

now i want to append '\' in the string so that when i print myline output is

C:\\Windows\\

Any idea or algo how to do this in C ?

copy the string one character at a time into another variable that is long enough to hold the extra characters. When an '\' is encountered just copy two of them.

But I have to question your reason for doing that. When you type a path from the keyboard into a variable you don't need the couble '\' characters. They are only needed when you use string literals in your program because the compiler has to interpret the characters.

OK.
Thanks for the suggestion.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.