Wow. Sorry I can't make much sense of this - attempted to drop the above function
parse_string()
into my existing program in order to compile and test it.
Lines 2 and 3 don't mean anything, a couple of global variables pointing to some other global variables, which don't actually exist.
Multiple compiler errors "\\" used which is interpreted as am escape sequence representing a single backslash. I think you meant "//" (forward slash). The implication is this isn't the actual code you were running, but something you have edited in a text editor but not actually compiled or run.
More important errors:
line 29:
length
is not defined
line 30, neither
recvd_buff
nor
recvd_chars
exist.
line 31,
recvd_buff[99]='\0';
why 99? seems to be just some arbitrary value pulled from thin air. How about using known information such as the value of
length
In any case, the source of the copy should be one of your pointers (p, p1, p2), the destination should be a an unused buffer area, I've no idea what your, recvd_buff is, for all I know it might be the same as the input, I've no idea.
Line 32,
|
p = strchr(recvd_buff, '\n'); \\ point the pointer to new array
|
As far as I can tell, this line set pointer p to the newline at the end of the data, thus there is no output at all.
What I suggest is this. Keep your functions simple, and self-contained. Don't have them relying on global variables lying around somewhere. Either declare local variables, or use the function parameters.
In terms of simplicity, rather than trying to patch new behaviour into existing code, consider breaking the task into smaller pieces and making the pieces into separate functions.
In this case I'm suggesting make the code to extract the substring between two newlines into a separate function.