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 03-30-2004, 07:14 PM   #1
THETEZ
LQ Newbie
 
Registered: Mar 2004
Distribution: Redhat 9
Posts: 6

Rep: Reputation: 0
whats a better way to do this


Code:
char dontneed[20];
char need[20];
char astring[40];

sscanf(astring , "%s %s",  dontneed,  need);
i dont need dontneed[], just need[]...whats better?
 
Old 03-30-2004, 07:51 PM   #2
wapcaplet
LQ Guru
 
Registered: Feb 2003
Location: Colorado Springs, CO
Distribution: Gentoo
Posts: 2,018

Rep: Reputation: 48
Perhaps you can use strtok() to skip to the second substring. It also looks (from reading the sscanf manpage) that you can use the format string '%*' to suppress assigning the matched portion to anything. Not having tried it, this is a guess:

Code:
sscanf(astring, "%* %s", need);
 
Old 03-31-2004, 04:46 AM   #3
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Debian, Mint, Puppy, Raspbian
Posts: 3,421

Rep: Reputation: 200Reputation: 200Reputation: 200
Maybe?

Code:
sscanf(astring , "%s %s",  need,  need);
then the second need overwrites the first?

billy
 
Old 03-31-2004, 05:51 PM   #4
itsme86
Senior Member
 
Registered: Jan 2004
Location: Oregon, USA
Distribution: Slackware
Posts: 1,246

Rep: Reputation: 59
strcpy(need, strchr(astring, ' ')+1);

Assuming you can always trust the input to have a space that is...
 
  


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
whats this mean? slinky2004 Linux - Newbie 3 10-09-2005 01:04 PM
whats next wesw02 Linux - Newbie 4 12-28-2004 01:17 PM
whats up with this?? A.D.D. Linux - Newbie 4 10-08-2004 02:47 AM
Whats this butface Linux - Newbie 4 08-25-2003 04:41 PM
So whats all this mean to me? WeNdeL Linux - Security 1 12-16-2002 11:02 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:00 AM.

Main Menu
Advertisement
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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration