Ok, so I posted earlier about trying (without any pre-configured features) to remove extra spaces so that
"this is <insert many spaces!> a test" will return
"this is a test"
Remove spaces from a string, but not at the beginning and end
As it was homework, I asked for no complete solutions, and some kind people provided me with the following
"If you need to do this in place, then create two pointers. One points to the character to be read and one to the character to be copied. When you encounter extra space, then use the" write "pointer to point to the next non-spatial character. Copy the character to the read position indicated by the write character, then move the read and write pointers to the character after the character to be copied.
The problem is that now I want to completely break my computer into pieces, since I annoy it so much. I did not understand that at that time I could not use the char array, so I used array indexes to do this, I thought I could tell how to make it work, but now I just use pointers, and it is very difficult for me. I really need help, not complete solutions. So far this is what I do;
1) create a pointer called write, so I have no where to write to
2) create a pointer called read, so I no where to read from
(both of these pointers now point to the first element of the char array)
while (read != '\0')
if read == a space
add one to read
if read equals a space now
add one to write
while read != a space {
set write to = read
}
add one to both read and write
else
add one to read and write
write = read
source
share