| | |
Putting Whitespaces and newlines
Thread Solved |
Need an example. you want to change "WethePeopleoftheUnitedStates" to this: "We the People of the United States" ? If the text is in a file then you will have to completly rewrite the file. First open the original file for reading, then another file for writing. In a loop read a line, modify it in memory as desired, then write the modified string to the output file.
Problem: how do you know where to add the spaces and new lines ?
Problem: how do you know where to add the spaces and new lines ?
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.
If this is schoolwork then your teacher should tell you how to do it. Otherwise, its nearly impossible for a program to check a string and add spaces where necessary to make it understandable to a human reader. You need to get more information from whoever gave you the requirements for the program.
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.
that should be fairly simple. First find the comma and back up one character. That is where you insert the space. Add another space immediately after the command, and a line feed one character beyone that. Do it with two string arrays -- the first is the original string and the second is the altered string.
I would write it for you, but I don't want to spoil all your fun
I would write it for you, but I don't want to spoil all your fun
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.
>>Could you explain the two string arrays further
You can't use the original string array to insert the spaces for a couple reasons
So to overcome those problems create another string array that is large enough to hold all the characters in the first plus the additional characters you want to add. Making the second array too large is ok, but too small can be a disaster waiting to happen.
You can't use the original string array to insert the spaces for a couple reasons
- the array may not be large enough to hold the additional characters.
- the array may be a literal and stored in read-only memory, any attempt to change it would probably crash the program.
So to overcome those problems create another string array that is large enough to hold all the characters in the first plus the additional characters you want to add. Making the second array too large is ok, but too small can be a disaster waiting to happen.
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.
![]() |
Other Threads in the C Forum
- Previous Thread: can i open a file in graphics mode ?
- Next Thread: scanning char array for \0 problem
| Thread Tools | Search this Thread |
* adobe api array arrays binarysearch calculate centimeter char cm convert copyanyfile copypdffile cprogramme createcopyoffile createprocess() csyntax directory dynamic feet fflush file floatingpointvalidation fork forloop frequency getlasterror getlogicaldrivestrin givemetehcodez global graphics gtkgcurlcompiling gtkwinlinux hacking hardware highest homework i/o ide inches incrementoperators intmain() iso km linked linkedlist linux linuxsegmentationfault list locate logical_drives loopinsideloop. match matrix microsoft motherboard mqqueue mysql oddnumber odf open opendocumentformat opensource openwebfoundation pattern pdf performance pointer posix power program programming pyramidusingturboccodes read recursion recv recvblocked repetition scanf scheduling segmentationfault send shape single socketprograming socketprogramming stack standard strchr string suggestions test unix urboc user variable voidmain() whythiscodecausesegmentationfault win32api windows.h






