Hello - I'm new to C programming (yes I have a book) and I've been working on a little project, which is a laptop deamon. It does some functions I need to monitor the health of my laptop. But that's besides the point (lol I love puns!). I'm trying to clean up some code - which takes a string and gets rid of all spaces.
That's it. Well I want to put this into a function to clean up my code (and make it more readable). But I've become lost at how to return pointers. I'm thinking of creating a function that would be run with CleanStream(StreamRead);. Similiar to strcmp(str1,str1), etc.Code:for(k = 0; k <= strlen(StreamRead); k++) { if(StreamRead[k] != ' ') { StreamClean[j] = StreamRead[k]; j++; } }
Here's where I'm at now:
So the whole idea would be ptrClean would return the location of StreamClean. But I don't know if the code works I wrote it by reading some source of some other codes. The second part which I don't understand is how to I set a variable to equal the data at the memory? Would something like StrSomevar = CleanStream(StreamRead); suffice?Code:char * CleanStream(const char * Str) { char StreamClean[128]; char *ptrClean; for(k = 0; k <= strlen(Str); k++) { if(Str[k] != ' ') { StreamClean[j] = Str[k]; j++; } } ptrClean = &StreamClean; return ptrClean; }
Have a good nigth (it's 12:51 right now),
-servo