LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
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, 06: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, 06: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, 03:46 AM   #3
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
Maybe?

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

billy
 
Old 03-31-2004, 04: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



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

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

All times are GMT -5. The time now is 03:45 PM.

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
Open Source Consulting | Domain Registration