| | |
Append a Character(backslash) to a string at any position
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
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\
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 ?
i have read a line from a text file & stored it in a string using fgets().
the file contains the following line:
C:\Windows\
C Syntax (Toggle Plain Text)
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.
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.
Last edited by Ancient Dragon; Jan 6th, 2009 at 10:05 am.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
![]() |
Similar Threads
- I've got Trojan.Holax... is this bad? (Viruses, Spyware and other Nasties)
- not-a-virusadware (Viruses, Spyware and other Nasties)
Other Threads in the C Forum
- Previous Thread: can't copy existing file into new file
- Next Thread: Optimized quicksort implementation
Views: 1018 | Replies: 2
| Thread Tools | Search this Thread |
Tag cloud for C
#include * append array arrays asterisks binarysearch calculate changingto char character cm command copyimagefile cprogramme creafecopyofanytypeoffileinc database directory dynamic execv feet fgets file fork forloop framework function functions givemetehcodez grade graphics gtkwinlinux hacking histogram homework include incrementoperators input intmain() iso kernel keyboard km lazy license linked linkedlist linux list lists locate logical_drives looping loopinsideloop. lowest matrix microsoft mqqueue mysql number oddnumber odf opensource overwrite owf pdf performance pointer pointers posix problem probleminc process program programming radix recursion recv recvblocked research reversing scanf scripting segmentationfault sequential socket spoonfeeding standard string student systemcall testing threads turboc unix user variable wab whythiscodecausesegmentationfault windowsapi






