Hi, is a strange request. I don't need a code. could somebody please explain me how it has to be done step by step. I just need the logic in for task.
Hi, is a strange request. I don't need a code. could somebody please explain me how it has to be done step by step. I just need the logic in for task.
What are "redundant white spaces", and what algorithm have you in mind?
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
lets say i have a string
I don't have any algo in my mind yetCode:"this is a string with redundant spaices in it"
All the white space in that string look pretty essential to meOriginally Posted by ph3s
What I am asking for is a definition of "redundant white space", and also an explicit statement of what does it mean to remove them. For example, maybe given your example string, your desired result is:
or maybe it is:Code:"this is a string with redundant spaices in it"
or maybe the string contain tab characters followed by space characters, and you only want to keep the first white space character, so you only keep the tab characters. Or maybe...Code:"thisisastringwithredundantspaicesinit"
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
O, I see. My bad. I meant if more than one white space among two words = redundancy.
Answer A in your assumptions
Last edited by ph3s; 03-18-2012 at 04:20 AM.
Okay, I give up. I guess if you don't want to be precise, then you're just going to have a hard time solving problems because you won't be able to think clearly
Anyway, here's one way to solve your problem, more or less:
Code:r = 0 w = 0 while string[r] is not a null character string[w] = string[r] increment r if string[w] is a white space character while string[r] is a white space character increment r increment w string[w] = null character
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
damn what I have done to curse me like that? Anyway thank you for hint and help.
Hey, it is just a conditional observation, not a curseOriginally Posted by ph3s
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
But I did exlained so you can see. Look at your post and examples. Which particular example you typed first?
C programming resources:
GNU C Function and Macro Index -- glibc reference manual
The C Book -- nice online learner guide
Current ISO draft standard
CCAN -- new CPAN like open source library repository
3 (different) GNU debugger tutorials: #1 -- #2 -- #3
cpwiki -- our wiki on sourceforge
We are all getting stressed from time to time, like me now. I just don't follow in this part of pseudo code.
Code:r = 0//got it w = 0/got it while string[r] is not a null character // that is ok string[w] = string[r]//yep all the steps to copy one increment r//string if string[w] is a white space character // right, lets say it meets ' ' while string[r] is a white space character//here I'm stack increment r //what for ? increment w// to another string[w] = null character // well yes, it has to end somewhere
Last edited by ph3s; 03-18-2012 at 11:30 AM.
The reason you increment r is to, well, skip the whitespace!
The cost of software maintenance increases with the square of the programmer's creativity. - Robert D. Bliss
If there is whitespace eliminated, the resulting string should be shorter than it started out as. Laserlight's algorithm works in-place (meaning, the input string is modified), so w represents the current index in the new string, and r the current index in the old string (it will be ahead of any changes made, then at the end the new version is null terminated).
C programming resources:
GNU C Function and Macro Index -- glibc reference manual
The C Book -- nice online learner guide
Current ISO draft standard
CCAN -- new CPAN like open source library repository
3 (different) GNU debugger tutorials: #1 -- #2 -- #3
cpwiki -- our wiki on sourceforge
Thanks gens and ladies. Now I can see. is Anythink looks wrong?
Code:main() { char redundant[]= "here is a messy string"; char proper[64]; int x=0, y=0; while ( redundant[x] != '\0') { proper[y]=redundant[x]; x++; if (proper[y] == ' ') { while (redundant[x]== ' ') x++; } y++; } proper[y]='\0'; printf("%s",proper); }
Last edited by ph3s; 03-18-2012 at 12:04 PM.
C programming resources:
GNU C Function and Macro Index -- glibc reference manual
The C Book -- nice online learner guide
Current ISO draft standard
CCAN -- new CPAN like open source library repository
3 (different) GNU debugger tutorials: #1 -- #2 -- #3
cpwiki -- our wiki on sourceforge