LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   how to get rid of the input beginning white spaces (https://www.linuxquestions.org/questions/programming-9/how-to-get-rid-of-the-input-beginning-white-spaces-236929/)

feetyouwell 09-29-2004 11:08 PM

how to get rid of the input beginning white spaces
 
Can anyone show me a quick way of getting rid of white spaces in c
for instance, user input
<space> <tab> <space> hello
and I use read () to get the entire line and store it in an array called buf[ ]
so my buff is stored wit useless white spaces, if I do a strlen(buf), it will return 3
how can I write a function that gets rid of all the while spaces and my buff just stores hello?

itsme86 09-29-2004 11:14 PM

Code:

  char *p = buf;

  while(*p == ' ' || *p == '\t')
    p++;

Now p will point to the first non-whitespace character in buf.

feetyouwell 09-29-2004 11:44 PM

thanks man, you've been my life saver, one quick question

*p++ = 0

that means, set *p to point to 0 and then increase pointer to the next item, right?

itsme86 09-30-2004 01:33 AM

*p++ = 0

means to change the value that p points to to 0 and then point to the next item.


All times are GMT -5. The time now is 07:21 AM.