LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices

Reply
 
Search this Thread
Old 08-29-2013, 07:54 PM   #1
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 3,125

Rep: Reputation: 46
Trying to make getopt work (C).


Hi: See this?

Code:
semoi@server:~$ cat t07.c 
#include <stdio.h>

int option;


main(int argc, char** argv){
	while((option= getopt(argc, argv, "vg")) != -1){
	switch(option){
		case 'v':
			printf("v\n");
			return;
		case 'g':
			printf("g\n");
			return;
	}
	}
}
semoi@server:~$ gcc -O2 -o t07 t07.c
semoi@server:~$ ./t07 v
semoi@server:~$ ./t07 g
semoi@server:~$
It should have printed 'v', then 'g'. What's wrong?
 
Old 08-29-2013, 07:59 PM   #2
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 3,125

Original Poster
Rep: Reputation: 46
I made a fool of myself. It's './t07 -g' I should have typed. Sorry.
 
Old 08-29-2013, 08:00 PM   #3
T3slider
Senior Member
 
Registered: Jul 2007
Distribution: Slackware64-14.1
Posts: 2,254

Rep: Reputation: 635Reputation: 635Reputation: 635Reputation: 635Reputation: 635Reputation: 635
getopt looks for options beginning with a hyphen (-). The following should work:
Code:
$ ./t07 -v
$ ./t07 -g
[edit] Too late. [/edit]
 
Old 08-29-2013, 08:07 PM   #4
perbh
Member
 
Registered: May 2008
Location: Republic of Texas
Posts: 241

Rep: Reputation: 38
yanno - I've been programming exclusively in 'c' for 20 years - and I still make mistakes like that!!
 
Old 08-29-2013, 09:42 PM   #5
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 3,125

Original Poster
Rep: Reputation: 46
Yes. But sometimes I find it easier to send a post rather than doing a little thinking, which is bad. Only sometimes.
 
Old 08-30-2013, 02:00 AM   #6
a4z
Member
 
Registered: Feb 2009
Posts: 417

Rep: Reputation: 138Reputation: 138
that is an interesting effect which I also know from my self,
having a question, write the question to a forum, post it, and as soon as you hit the post button the answer pops up in your brain.
 
Old 08-30-2013, 03:01 AM   #7
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 3,125

Original Poster
Rep: Reputation: 46
The problem is that there are things one only considers as a means. Having the end in mind, I gets impatient and I want to get over it as soon as possible. After all, it's all about we people fond of open source getting in touch with one another, and learning by the way, a thing I love.

Last edited by stf92; 08-30-2013 at 03:41 AM.
 
Old 08-30-2013, 03:36 AM   #8
GazL
Senior Member
 
Registered: May 2008
Posts: 3,392

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
If you make a habit of posting trivial questions that can be solved by a google search, reading the man-page, or even just a few seconds of thought then people will soon tire of you and add you to their ignore list. It's something to keep in mind before you hit that 'submit' button.

Posting to the wrong forum won't help either: what did this question have to do with Slackware?

Last edited by GazL; 08-30-2013 at 03:40 AM.
 
Old 08-30-2013, 03:45 AM   #9
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 3,125

Original Poster
Rep: Reputation: 46
You think LQ is the oracle of Delphi? If you do, you are wrong. I am prone to believe it's more like a place where people gets in touch with people who know, devoided of solemnity.

And was not completely sincere when speaking about means and ends. Sometimes the means are even more interesting then the end.

Last edited by stf92; 08-30-2013 at 03:49 AM.
 
Old 08-30-2013, 04:04 AM   #10
GazL
Senior Member
 
Registered: May 2008
Posts: 3,392

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
Take the warning for what it is, or ignore it if you like. It's no skin off my nose if you end up on ignore lists.
 
  


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
LXer: Many hands make the light work; few make it shine LXer Syndicated Linux News 0 06-08-2010 04:20 AM
make Xconfig doesn't work, make menuconfig does work Debian/KDE bucovaina78 Linux - Kernel 1 10-15-2008 01:26 PM
1st time installing redhat - Make and Make Install does not work runlikeanantelope Linux - Newbie 4 02-19-2007 03:58 PM
How do I make a change to a current kernel? Would 'make oldconfig' work... jtp51 Slackware 11 11-01-2004 11:02 PM
configure, make and make install commands don't work for me Fenster Fedora 8 08-18-2004 10:58 AM


All times are GMT -5. The time now is 05:31 PM.

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