0

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 ?

2
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by CoolAtt
0

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.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.