LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 09-29-2004, 11:08 PM   #1
feetyouwell
Member
 
Registered: Dec 2003
Location: NC, US
Distribution: Novell Linux Eval (2.6.5)
Posts: 240

Rep: Reputation: 30
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?
 
Old 09-29-2004, 11:14 PM   #2
itsme86
Senior Member
 
Registered: Jan 2004
Location: Oregon, USA
Distribution: Slackware
Posts: 1,246

Rep: Reputation: 58
Code:
  char *p = buf;

  while(*p == ' ' || *p == '\t')
    p++;
Now p will point to the first non-whitespace character in buf.
 
Old 09-29-2004, 11:44 PM   #3
feetyouwell
Member
 
Registered: Dec 2003
Location: NC, US
Distribution: Novell Linux Eval (2.6.5)
Posts: 240

Original Poster
Rep: Reputation: 30
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?
 
Old 09-30-2004, 01:33 AM   #4
itsme86
Senior Member
 
Registered: Jan 2004
Location: Oregon, USA
Distribution: Slackware
Posts: 1,246

Rep: Reputation: 58
*p++ = 0

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


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Ctrl+Shift Unicode input gone, after installing Japanese Input Methodes polemon Linux - Newbie 1 09-20-2005 05:17 PM
problems in removing white spaces from string of text monil Programming 7 03-08-2005 11:28 AM
Remove white spaces in HTML files using shell : Possible???????? cpanelskindepot Programming 2 08-05-2004 11:14 PM
Sendmail: timeout waiting for input from local during Draining Input andrewstr Linux - Software 0 07-14-2004 01:43 PM
Getting rid of "\" before spaces in filenames when using the ls command Locura Linux - Distributions 8 07-05-2003 10:19 PM


All times are GMT -5. The time now is 09:34 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration