Latest LQ Deal: Linux Power User Bundle
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 03-30-2004, 06:14 PM   #1
LQ Newbie
Registered: Mar 2004
Distribution: Redhat 9
Posts: 6

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

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
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:

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

Rep: Reputation: 200Reputation: 200Reputation: 200

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

Old 03-31-2004, 04:51 PM   #4
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...


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 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 > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:47 PM.

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