LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > General
User Name
Password
General This forum is for non-technical general discussion which can include both Linux and non-Linux topics. Have fun!

Notices


Closed Thread
  Search this Thread
Old 01-15-2010, 05:25 AM   #106
barboolian
Member
 
Registered: Dec 2009
Posts: 32

Rep: Reputation: 15

Somewhere else: Belgium
 
Old 01-15-2010, 05:30 AM   #107
brianL
LQ 5k Club
 
Registered: Jan 2006
Location: Oldham, Lancs, England
Distribution: Slackware64 15; SlackwareARM-current (aarch64); Debian 12
Posts: 8,302
Blog Entries: 61

Rep: Reputation: Disabled
Or an alternative universe.
 
Old 01-15-2010, 05:46 AM   #108
lupusarcanus
Senior Member
 
Registered: Mar 2009
Location: USA
Distribution: Arch
Posts: 1,022
Blog Entries: 19

Rep: Reputation: 146Reputation: 146
Or an alternative dimension.
 
Old 01-15-2010, 05:52 AM   #109
brianL
LQ 5k Club
 
Registered: Jan 2006
Location: Oldham, Lancs, England
Distribution: Slackware64 15; SlackwareARM-current (aarch64); Debian 12
Posts: 8,302
Blog Entries: 61

Rep: Reputation: Disabled
Yes, turn left at the next alternative universe and you'll be in an alternative dimension.
Don't turn right, or you'll fall off the edge.

Last edited by brianL; 01-15-2010 at 05:53 AM.
 
Old 01-15-2010, 07:34 AM   #110
barboolian
Member
 
Registered: Dec 2009
Posts: 32

Rep: Reputation: 15
In an alternative dimension there are lots of ways to turn other than left or right. Anyway, how do you know
whether Belgium is an alternative dimension?
 
Old 01-15-2010, 07:36 AM   #111
brianL
LQ 5k Club
 
Registered: Jan 2006
Location: Oldham, Lancs, England
Distribution: Slackware64 15; SlackwareARM-current (aarch64); Debian 12
Posts: 8,302
Blog Entries: 61

Rep: Reputation: Disabled
I don't believe Belgium exists in any dimension.
 
Old 01-15-2010, 07:45 AM   #112
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723
Quote:
Originally Posted by MrCode View Post
Okay, I've revised it so that gcc doesn't put out any errors/warnings:

Code:
#include <stdlib.h>
#include <stdio.h>

char answer1[] = "Not much.";
char answer2[] = "Something you don't need to know about";
char answer3[] = "Why do you care?";

int main(char* argc[],int argv)
{
    if(strcmp(argc,"What\'s-up?") > 0)
        printf("%s",answer1);
    else if(strcmp(argc,"Whatcha-doing?") > 0)
        printf("%s",answer2);
    else if(strcmp(argc,"How\'re you-doing?") > 0)
        printf("%s",answer3);
    else
        return 0;
}
...but I still get a segfault when I try to run it:

Code:
mrcode@linuxbox:~/Programs$ gcc askme.c -g -O9 -o askme
mrcode@linuxbox:~/Programs$ ./askme Watcha-doing?
Segmentation fault
Is it because I'm trying to compare argc with a string literal?

EDIT: It also segfaults even when no argument is passed (when it should just return normally...?)

(Note: I can start a new thread in the Programming forum if need be...I apologize for hijacking this one)
argc is an array of pointers to strings, not a pointer to a string.

Also, it's:
Code:
int main(int argc, char* argv[])
not:
Code:
int main(char* argc[],int argv)
Also, argc is the count of arguments, argv is an array of pointers. argv[0] is the text you used to launch the program.

Code:
$ cat stuff.c             
#include <stdio.h>            
#include <stdlib.h>           

int main(int argc, char* argv[]) {
        int i;                    
    for(i=0; i<argc; i++) {       
                puts(argv[i]);    
        }                         
}                                 
$ gcc stuff.c -o stuff
$ ./stuff
./stuff
$ ./stuff One
./stuff
One
$ ./stuff One Two
./stuff
One
Two
 
Old 01-15-2010, 08:10 AM   #113
carbonfiber
Member
 
Registered: Sep 2009
Location: Sparta
Posts: 237

Rep: Reputation: 46
1. man gcc FTW
2. -std=c99 -pedantic -Wall -Wextra FTW
3. wrong thread FTW
 
Old 01-15-2010, 09:04 AM   #114
MBybee
Member
 
Registered: Jan 2009
Location: wherever I can make a living
Distribution: OpenBSD / Debian / Ubuntu / Win7 / OpenVMS
Posts: 440

Rep: Reputation: 57
I'd say it's telling you what it's doing - it's SEGFAULTing
 
Old 01-15-2010, 09:43 AM   #115
GoinEasy9
Member
 
Registered: Feb 2004
Location: Manorville, New York, USA
Distribution: siduction, openSUSE Tumbleweed
Posts: 379
Blog Entries: 1

Rep: Reputation: 47
"Can you hear me Segfaulting now"?

Edit: BTW
Begin
Watching Dog chew leg on antique desk
Again

Last edited by GoinEasy9; 01-15-2010 at 09:45 AM.
 
Old 01-15-2010, 09:55 AM   #116
brianL
LQ 5k Club
 
Registered: Jan 2006
Location: Oldham, Lancs, England
Distribution: Slackware64 15; SlackwareARM-current (aarch64); Debian 12
Posts: 8,302
Blog Entries: 61

Rep: Reputation: Disabled
Watching this on BBC iPlayer:

http://www.bbc.co.uk/iplayer/episode...ighting_Women/
 
Old 01-15-2010, 10:09 AM   #117
GoinEasy9
Member
 
Registered: Feb 2004
Location: Manorville, New York, USA
Distribution: siduction, openSUSE Tumbleweed
Posts: 379
Blog Entries: 1

Rep: Reputation: 47
Quote:
Watching this on BBC iPlayer:

http://www.bbc.co.uk/iplayer/episode...ighting_Women/
Actually glad this isn't available outside UK.

Waiting for a Public Citizen Webinar that starts at 12 noon EST
 
Old 01-15-2010, 12:31 PM   #118
MrCode
Member
 
Registered: Aug 2009
Location: Oregon, USA
Distribution: Arch
Posts: 864
Blog Entries: 31

Rep: Reputation: 148Reputation: 148
Quote:
Originally Posted by MTK358 View Post
argc is an array of pointers to strings, not a pointer to a string.

Also, it's:
Code:
int main(int argc, char* argv[])
not:
Code:
int main(char* argc[],int argv)
Also, argc is the count of arguments, argv is an array of pointers. argv[0] is the text you used to launch the program.

Code:
$ cat stuff.c             
#include <stdio.h>            
#include <stdlib.h>           

int main(int argc, char* argv[]) {
        int i;                    
    for(i=0; i<argc; i++) {       
                puts(argv[i]);    
        }                         
}                                 
$ gcc stuff.c -o stuff
$ ./stuff
./stuff
$ ./stuff One
./stuff
One
$ ./stuff One Two
./stuff
One
Two
Thanks...I looked at another site trying to fix a different problem (completely unrelated to this one), and I found that it is indeed

Code:
 int main(int argc,char* argv[])
It's working now (sort of), and I'm actually thinking about maybe taking this further and making a simple Q/A-based AI out of it (with hard-coded answers; nothing too special).

Anyways, I'll go ahead and shut up about it now; it's working, and there's no reason I should be hijacking the thread anymore.

(I know how to pass arguments now! )

Last edited by MrCode; 01-15-2010 at 12:41 PM.
 
Old 01-15-2010, 12:42 PM   #119
smeezekitty
Senior Member
 
Registered: Sep 2009
Location: Washington U.S.
Distribution: M$ Windows / Debian / Ubuntu / DSL / many others
Posts: 2,339

Rep: Reputation: 231Reputation: 231Reputation: 231
You may also want to change "strcmp" to "strcmpi" so it is not case sensitive.
 
Old 01-15-2010, 01:00 PM   #120
carbonfiber
Member
 
Registered: Sep 2009
Location: Sparta
Posts: 237

Rep: Reputation: 46
Quote:
Originally Posted by MrCode View Post
It's working now (sort of), and I'm actually thinking about maybe taking this further and making a simple Q/A-based AI out of it (with hard-coded answers; nothing too special).
Or, indeed, special at all.

What I am doing now: being honest and an arsehole :P

Last edited by carbonfiber; 01-16-2010 at 03:50 PM.
 
  


Closed Thread



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



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

All times are GMT -5. The time now is 01:35 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