LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   General (https://www.linuxquestions.org/questions/general-10/)
-   -   What are you doing now? (https://www.linuxquestions.org/questions/general-10/what-are-you-doing-now-781491/)

MTK358 01-14-2010 08:13 PM

I thought that a segfault means that the program tried to read/write memory that it did not allocate.

MrCode 01-14-2010 08:20 PM

Quote:

I thought that a segfault means that the program tried to read/write memory that it did not allocate.
...yeah, I suppose I really need to go do some reading up on the subject...

:o

*opens tabs for cplusplus.com and Wikipedia*

EDIT: Actually, Wikipedia lists "attempt to access memory the program does not own" as one of the causes of a segfault, so I guess I was kind of right the first time, but yes, trying to read/write to unallocated memory (or dereferencing it) will do the same thing. :)

MrCode 01-14-2010 10:37 PM

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)

brianL 01-15-2010 04:51 AM

I read the Wikipedia article, but don't know enough to see where that program is "attempting to access memory the program does not own".
Whatever you're typing now is what you're doing now. So really, it's impossible to hijack this thread. :)

raju.mopidevi 01-15-2010 05:16 AM

this thread started with some thing .... going to ..... some where else ....

barboolian 01-15-2010 05:25 AM

Somewhere else: Belgium

brianL 01-15-2010 05:30 AM

Or an alternative universe.

lupusarcanus 01-15-2010 05:46 AM

Or an alternative dimension.

brianL 01-15-2010 05:52 AM

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.

barboolian 01-15-2010 07:34 AM

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?

brianL 01-15-2010 07:36 AM

I don't believe Belgium exists in any dimension.

MTK358 01-15-2010 07:45 AM

Quote:

Originally Posted by MrCode (Post 3827070)
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


carbonfiber 01-15-2010 08:10 AM

1. man gcc FTW
2. -std=c99 -pedantic -Wall -Wextra FTW
3. wrong thread FTW

MBybee 01-15-2010 09:04 AM

I'd say it's telling you what it's doing - it's SEGFAULTing ;)

GoinEasy9 01-15-2010 09:43 AM

"Can you hear me Segfaulting now"?

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

brianL 01-15-2010 09:55 AM

Watching this on BBC iPlayer:

http://www.bbc.co.uk/iplayer/episode...ighting_Women/

GoinEasy9 01-15-2010 10:09 AM

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

MrCode 01-15-2010 12:31 PM

Quote:

Originally Posted by MTK358 (Post 3827476)
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! :D)

smeezekitty 01-15-2010 12:42 PM

You may also want to change "strcmp" to "strcmpi" so it is not case sensitive.

carbonfiber 01-15-2010 01:00 PM

Quote:

Originally Posted by MrCode (Post 3827780)
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

MrCode 01-15-2010 02:13 PM

Quote:

What I am doing now: being honest and an arshole :P
Yes, yes you are :p

But seriously, I know it's nothing to shout about...I'm mainly just doing it for the practice (you could say I'm still a programming n00b).

What I'm doing now: trying to get the program to work...

barboolian 01-16-2010 06:13 AM

Quote:

Originally Posted by carbonfiber (Post 3827814)
What I am doing now: being honest and an arshole :P

That one is an arshole immaterial if one is a genuine arshole.

brianL 01-16-2010 09:18 AM

Thinking...

colucix 01-16-2010 11:13 AM

I don't know what "arshole" means so I'm not thinking... just typing...

brianL 01-16-2010 11:15 AM

it's missing an "e".

minrich 01-16-2010 11:20 AM

That reminds me that, many years ago, when I worked for an internaional bank, I was lucky enough never to get posted to 'our Seoul' branch.

colucix 01-16-2010 12:49 PM

So it's earshole! Thanks Brian... hmmm... thinking now...

brianL 01-16-2010 01:10 PM

Hahaha...yes...that's right.

carbonfiber 01-16-2010 03:51 PM

I spelled it correctly, check my post. It's not my fault people try to spread LIES about what I said.

brianL 01-16-2010 03:54 PM

You mean post #120, with this:
Last edited by carbonfiber; Today at 09:50 PM..

minrich 01-16-2010 04:04 PM

I think we will have to call in jeremy - to ascertain exactly what was changed by carbonfiber at 9.50 Grenitch Me'ning Time (what was he thinking) - this is after all the "What are you doing now" not the "what werw you doing 15 minutes ago" thread!

lupusarcanus 01-16-2010 04:08 PM

Well.

carbonfiber 01-16-2010 04:37 PM

I would have gotten away with it too if it weren't for you meddling brianL.

brianL 01-16-2010 04:43 PM

:D:D:D

brianL 01-16-2010 05:03 PM

Going to watch "The Cell" on TV.

raju.mopidevi 01-16-2010 06:45 PM

Just browsing through LQ

Tinkster 01-16-2010 06:51 PM

Waiting for this threads natural death ...

brianL 01-16-2010 06:55 PM

Quote:

Originally Posted by Tinkster (Post 3829130)
Waiting for this threads natural death ...

Checking its pulse...very weak. Yes, it's going.

minrich 01-16-2010 07:21 PM

No it isn't .. I just check and now is now and your post was your now, not my now.

This is the thread that never ends, it just goes on and on my friends ... because 'now' is something of a moving target.

GrapefruiTgirl 01-16-2010 07:25 PM

Quote:

Originally Posted by minrich (Post 3829161)
... because 'now' is something of a moving target.

Hm. Just like a Slackware release date ;)

Jeebizz 01-16-2010 08:13 PM

I am foolishly trying to divide by 0. One day I will be successful!!!!! It will work, and I know it will have worked because the fabric of space will tear, and all that we know will suddenly...

smeezekitty 01-16-2010 08:18 PM

Quote:

Originally Posted by Jeebizz (Post 3829204)
I am foolishly trying to divide by 0. One day I will be successful!!!!! It will work, and I know it will have worked because the fabric of space will tear, and all that we know will suddenly...

It does work, the answer is infinity.

MrCode 01-17-2010 12:50 AM

Quote:

It does work, the answer is infinity.
*hole rips in the fabric of space-time*

OSHI-!

You've killed us all! :p

jayjwa 01-17-2010 01:59 AM

Trying to login to mozilla's horrifically broken website to report that an addon (clickweather, 1.1.9, https://addons.mozilla.org/en-US/firefox/addon/1035 and read the reviews) bricked my brower. Going back to an old version isn't possible because their mask out the old versions with some sort of "don't let the user install this" code. 1.1.8 worked here 5 minutes ago, now I'm told it "won't work with my version". No prob., I'll leave a note for the developer. That requires signing up. Their registration process chases its own tail and goes in "type what you see" circles, then they finish by mailing from a user "nobody". How does "nobody" send mail? This is also the default user of a compromised Apache install, so lots and lots of spam/phish also comes from "nobody". Registration attempt #1 killed by junk mail rules. Attempt #2 to gmail since I'm not letting my own mailserver drop trousers just to accomodate mozilla.org's bad mail practices. As it turns out, even with successful registration, you can't login, even with cookies, javascript, java, and the kitchen sink enabled. Keep clicking "login" and you'll end back at .... login or register. Thus, there's no way to tell the developer that his extension is flopping and users and abandoning it like a sinking ship. His "contact" link sends you to weather.com, where you might be able to guess there's no real contact email, only....drum roll please.... more broken Javascript web registration code! I give up. clickweather axed. I'm sending Firefox to the fur coat factory.

This is a dream, right? A nightmare - someone wake me!

lupusarcanus 01-17-2010 02:06 AM

Quote:

Originally Posted by jayjwa (Post 3829419)
Trying to login to mozilla's horrifically broken website to report that an addon (clickweather, 1.1.9, https://addons.mozilla.org/en-US/firefox/addon/1035 and read the reviews) bricked my brower. Going back to an old version isn't possible because their mask out the old versions with some sort of "don't let the user install this" code. 1.1.8 worked here 5 minutes ago, now I'm told it "won't work with my version". No prob., I'll leave a note for the developer. That requires signing up. Their registration process chases its own tail and goes in "type what you see" circles, then they finish by mailing from a user "nobody". How does "nobody" send mail? This is also the default user of a compromised Apache install, so lots and lots of spam/phish also comes from "nobody". Registration attempt #1 killed by junk mail rules. Attempt #2 to gmail since I'm not letting my own mailserver drop trousers just to accomodate mozilla.org's bad mail practices. As it turns out, even with successful registration, you can't login, even with cookies, javascript, java, and the kitchen sink enabled. Keep clicking "login" and you'll end back at .... login or register. Thus, there's no way to tell the developer that his extension is flopping and users and abandoning it like a sinking ship. His "contact" link sends you to weather.com, where you might be able to guess there's no real contact email, only....drum roll please.... more broken Javascript web registration code! I give up. clickweather axed. I'm sending Firefox to the fur coat factory.

This is a dream, right? A nightmare - someone wake me!

Thank Lord I trust my browsing to Google Chrome.
Can't say much other than there some arsehole out there F****** with people.
I guess I can say I hope whatever happens you get it worked out all right.

barboolian 01-17-2010 03:41 AM

Quote:

Originally Posted by jayjwa (Post 3829419)
his extension is flopping

I get spam email about a cure for that.

brianL 01-17-2010 05:53 AM

rotfl

lupusarcanus 01-17-2010 06:49 AM

And lo, I acquiescently exclaim, my "Google!" paraphernalia from afar, whilst said illusion of subjugated mediocracy was consummated in an elicit explicit harrowing abend inadvertently kindling exasperation until the culmination of incontrovertible and irrevocable affirmation of plenary cessation by reason of precarious overture when undertaking rather bourgeois video and flash entertainment. Quotidian avocation shall envisage consistent, stable efficacy.

Man, I am bored.

brianL 01-17-2010 06:52 AM

Quote:

Originally Posted by leopard (Post 3829601)
And lo, I acquiescently exclaim, my "Google!" paraphernalia from afar, whilst said illusion of subjugated mediocracy was consummated in an elicit explicit harrowing abend inadvertently kindling exasperation until the culmination of incontrovertible and irrevocable affirmation of plenary cessation by reason of precarious overture when undertaking rather bourgeois video and flash entertainment. Quotidian avocation shall envisage consistent, stable efficacy.

Huh? Could you repeat that?

lupusarcanus 01-17-2010 06:59 AM

Quote:

Originally Posted by brianL (Post 3829604)
Huh? Could you repeat that?

It's an English puzzle, LOL. I was really bored and had something to say here, so I though I'd make a little fun out of it.

So...

I was happily browsing Youtube...

And lo, I acquiescently exclaim, my "Google!" paraphernalia from afar, whilst said illusion of subjugated mediocracy was consummated in an elicit explicit harrowing abend inadvertently kindling exasperation until the culmination of incontrovertible and irrevocable affirmation of plenary cessation by reason of precarious overture when undertaking rather bourgeois video and flash entertainment. Quotidian avocation shall envisage consistent, stable efficacy.

Dang.


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