| | |
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: 1011 | Replies: 2
| Thread Tools | Search this Thread |
Tag cloud for C
#include * append array arrays bash binarysearch changingto char character cm command copyanyfile copypdffile createprocess() database directory drawing dynamic execv feet fgets file floatingpointvalidation fork framework function functions getlogicaldrivestrin givemetehcodez global grade graphics gtkwinlinux histogram homework i/o ide include infiniteloop initialization input interest intmain() iso keyboard kilometer lazy license linked linkedlist linux list looping loopinsideloop. lowest matrix meter microsoft mqqueue oddnumber odf open openwebfoundation overwrite pause pdf pointer pointers posix power process program programming pyramidusingturboccodes read recursion recv recvblocked reversing segmentationfault single socket socketprogramming spoonfeeding standard strchr string student suggestions system test testing threads unix urboc user whythiscodecausesegmentationfault win32api windowsapi






