473,503 Members | 2,105 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Passing args to main( )

ern
I want to pass arguments to the main( ) function of my C program.
Currently, I'm using

main(char * args)

But when I try to print args, I get an unhandled exception error. Is
there a better, safer way to pass args to main (from another [python]
module) ?

Mar 3 '06 #1
17 3227
ern wrote:
I want to pass arguments to the main( ) function of my C program.
Currently, I'm using

main(char * args)

But when I try to print args, I get an unhandled exception error. Is
there a better, safer way to pass args to main (from another [python]
module) ?

There are only two portable signatures (modulo synonyms) for the main()
function in C:

int main(void) /* taking no arguments */

or

int main(int argc, char **argv) /* with arguments */

Anything else is non-standard.

HTH,
--ag

--
Artie Gold -- Austin, Texas
http://goldsays.blogspot.com
"You can't KISS* unless you MISS**"
[*-Keep it simple, stupid. **-Make it simple, stupid.]
Mar 3 '06 #2
ern wrote:
I want to pass arguments to the main( ) function of my C program.
Currently, I'm using

main(char * args)

But when I try to print args, I get an unhandled exception error. Is
there a better, safer way to pass args to main (from another [python]
module) ?


The only portable way of passing arguments to `main` is declaring it as:

int main(int argc, char *argv[])

and pass things on the command line. Judging by your post, you'd be
easily able to do it.

BTW, `argc` gives you the total number of arguments passed, and `argv`
is an array of pointers to strings containing them. Keep in mind that
program name is always the first argument. How it, as well as how other
arguments look like depends on your particular system. Standard does
not specify this, and hence it's off-topic here. You're better off
asking that part of the question in the group specific to your
environment.

--
BR, Vladimir

"If you've done six impossible things before breakfast, why not round
it off with dinner at Milliway's, the restaurant at the end of the
universe?"

Mar 3 '06 #3
On 2006-03-03, ern <er*******@gmail.com> wrote:
I want to pass arguments to the main( ) function of my C program.
Currently, I'm using

main(char * args)

But when I try to print args, I get an unhandled exception error. Is
there a better, safer way to pass args to main (from another [python]
module) ?


main(int argc, char *argv[])
Mar 3 '06 #4
On 2006-03-03, Vladimir S. Oka <no****@btopenworld.com> wrote:
Keep in mind that program name is always the first argument.


*cough-OT-execl-path-(char*)NULL-/OT-/cough*

Which is why 5.1.2.2.1 keeps saying "If the value of argc is greater
than zero".
Mar 3 '06 #5
ern wrote:
I want to pass arguments to the main( ) function of my C program.
Currently, I'm using

main(char * args)

But when I try to print args, I get an unhandled exception error. Is
there a better, safer way to pass args to main (from another [python]
module) ?


This is not of the two forms of main() required to be supported. Your
textbook should show you the right way to handle arguments. What book
are you using?

At any rate, see the FAQs:

http://c-faq.com/ansi/maindecl.html
Brian

--
Please quote enough of the previous message for context. To do so from
Google, click "show options" and use the Reply shown in the expanded
header.
Mar 3 '06 #6
Jordan Abel ha scritto:
On 2006-03-03, ern <er*******@gmail.com> wrote:
I want to pass arguments to the main( ) function of my C program.
Currently, I'm using

main(char * args)

But when I try to print args, I get an unhandled exception error. Is
there a better, safer way to pass args to main (from another [python]
module) ?

main(int argc, char *argv[])


<OT>
Just a note (not trolling, nor joking). Why posting something that
someone else already posted? I mean, what's the reason for replying
"main(int argc, char *argv[])", when this answer was already given by
Artie Gold, and when Vladimir S. Oka gave the full explanation of argc
and argv[]? I mean, your answer is only filling server's bandwidth, it's
not giving any detail missing in the previous answers, come on! I don't
really see the reason of giving an already given answer. It's not a
personal thing to you (Jordan Abel), but a general question: I've seen
threads spreading, and getting bigger and bigger, with lots of replies,
each giving the same responses. Is this normal? Am I strange? Crazy?
What? Maybe I missed for too much time from Usenet and the rules changed?
I repeat, I'm not trolling, nor flaming, nor everything else you can
think of. I'm just exposing my opinion.
</OT>

Regards,
David

P.S.: if you, like anyone else, want, we could open a thread about this.
I know, it's completely OT, but I think it's important for the «health»
of Usenet. It's a matter of behaviours.
--
Linux Registered User #334216
Get FireFox! >> http://www.spreadfirefox.com/?q=affiliates&id=48183&t=1
Staff >> http://www.debianizzati.org <<
Mar 3 '06 #7
Jordan Abel <ra*******@gmail.com> writes:
On 2006-03-03, ern <er*******@gmail.com> wrote:
I want to pass arguments to the main( ) function of my C program.
Currently, I'm using

main(char * args)

But when I try to print args, I get an unhandled exception error. Is
there a better, safer way to pass args to main (from another [python]
module) ?


main(int argc, char *argv[])


"int", main's return type, is spelled with three letters, not zero.
HTH, HAND.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Mar 3 '06 #8
On 2006-03-03, David Paleino <d.*******@gmail.com> wrote:
Just a note (not trolling, nor joking). Why posting something that
someone else already posted?
I didn't see it yet. This is part of a larger issue, see below.
Maybe I missed for too much time from Usenet and the rules changed?


Usenet has always been a distributed, asynchronous medium. This
sometimes has some unfortunate consequences. It becomes most apparent
when a question [like this one] has an easy answer because:

A) everyone's responses look pretty much alike

B) more people respond on average

and

C) people respond quickly.
Mar 3 '06 #9
On 2006-03-03, Keith Thompson <ks***@mib.org> wrote:
Jordan Abel <ra*******@gmail.com> writes:
On 2006-03-03, ern <er*******@gmail.com> wrote:
I want to pass arguments to the main( ) function of my C program.
Currently, I'm using

main(char * args)

But when I try to print args, I get an unhandled exception error. Is
there a better, safer way to pass args to main (from another [python]
module) ?


main(int argc, char *argv[])


"int", main's return type, is spelled with three letters, not zero.
HTH, HAND.


There are zero letters in an alternate spelling that is accepted, though
marked obsolescent, in c89.
Mar 3 '06 #10
David Paleino said:
Just a note (not trolling, nor joking). Why posting something that
someone else already posted?


Usenet is not a chat network. Updates are done in unsynchronised batches
from server to server, as and when each server sees fit. Articles that have
already appeared on /your/ server may not yet have appeared on someone
else's server. Therefore that other person might well not have seen the
other response at the time they composed and submitted their own.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Mar 3 '06 #11
On 2006-03-03, Richard Heathfield <in*****@invalid.invalid> wrote:
David Paleino said:
Just a note (not trolling, nor joking). Why posting something that
someone else already posted?
Usenet is not a chat network.


Funny disanalogy, since many chat networks have the same problem, though
on a scale more likely to be measured in seconds than [potentially]
days. And, indeed, when someone asks an easy question on IRC, easily
half a dozen people will jump to give the exact same answer in some of
the busier channels.
Updates are done in unsynchronised batches from server to server, as
and when each server sees fit. Articles that have already appeared on
/your/ server may not yet have appeared on someone else's server.
Therefore that other person might well not have seen the other
response at the time they composed and submitted their own.

Mar 3 '06 #12
Jordan Abel said:
And, indeed, when someone asks an easy question on IRC, easily
half a dozen people will jump to give the exact same answer in some of
the busier channels.


To be more specific, the exact same /wrong/ answer. :-)

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Mar 3 '06 #13
Jordan Abel wrote:
On 2006-03-03, Richard Heathfield <in*****@invalid.invalid> wrote:
David Paleino said:
Just a note (not trolling, nor joking). Why posting something that
someone else already posted?


Usenet is not a chat network.


Funny disanalogy, since many chat networks have the same problem, though
on a scale more likely to be measured in seconds than [potentially]
days. And, indeed, when someone asks an easy question on IRC, easily
half a dozen people will jump to give the exact same answer in some of
the busier channels.
Updates are done in unsynchronised batches from server to server, as
and when each server sees fit. Articles that have already appeared on
/your/ server may not yet have appeared on someone else's server.
Therefore that other person might well not have seen the other
response at the time they composed and submitted their own.


<OT>
This is also the reason why you should always quote the context of your
replies on Usenet since there are times when people simply cannot 'see'
the context simply because your reply arrives early.
</OT>

Mar 4 '06 #14
On 2006-03-03, sl*******@yahoo.com <sl*******@gmail.com> wrote:
Jordan Abel wrote:
On 2006-03-03, Richard Heathfield <in*****@invalid.invalid> wrote:
> David Paleino said:
>
>> Just a note (not trolling, nor joking). Why posting something that
>> someone else already posted?
>
> Usenet is not a chat network.
Funny disanalogy, since many chat networks have the same problem, though
on a scale more likely to be measured in seconds than [potentially]
days. And, indeed, when someone asks an easy question on IRC, easily
half a dozen people will jump to give the exact same answer in some of
the busier channels.
> Updates are done in unsynchronised batches from server to server, as
> and when each server sees fit. Articles that have already appeared on
> /your/ server may not yet have appeared on someone else's server.
> Therefore that other person might well not have seen the other
> response at the time they composed and submitted their own.


<OT>
This is also the reason why you should always quote the context of your
replies on Usenet since there are times when people simply cannot 'see'
the context simply because your reply arrives early.


Fortunately, IRC doesn't have such a failing, because of the
spanning-tree layout of the network. Usenet does not necessarily have
such a layout.
</OT>

Mar 4 '06 #15
Richard Heathfield ha scritto:

...

Usenet is not a chat network.
Fully agree :)
Updates are done in unsynchronised batches
from server to server, as and when each server sees fit. Articles that have
already appeared on /your/ server may not yet have appeared on someone
else's server. Therefore that other person might well not have seen the
other response at the time they composed and submitted their own.


Erm... I just didn't think about different syncing times, sorry for
that... Maybe is my server that is just too fast :P (/me is joking,
obviously)

Regards,
David

--
Linux Registered User #334216
Get FireFox! >> http://www.spreadfirefox.com/?q=affiliates&id=48183&t=1
Staff >> http://www.debianizzati.org <<
Mar 4 '06 #16

Richard Heathfield <in*****@invalid.invalid> writes:
David Paleino said:
Just a note (not trolling, nor joking). Why posting something that
someone else already posted?


Usenet is not a chat network. Updates are done in unsynchronised batches
from server to server, as and when each server sees fit. Articles that have
already appeared on /your/ server may not yet have appeared on someone
else's server. Therefore that other person might well not have seen the
other response at the time they composed and submitted their own.


Another possible reason is that people post a reply before they have
read all other replies. Not that I intend to accuse the people in question
here of doing that.
Mar 8 '06 #17
On 3 Mar 2006 22:45:06 GMT, Jordan Abel <ra*******@gmail.com> wrote:
On 2006-03-03, Keith Thompson <ks***@mib.org> wrote:

"int", main's return type, is spelled with three letters, not zero.
HTH, HAND.


There are zero letters in an alternate spelling that is accepted, though
marked obsolescent, in c89.


Nit: implicit int, and implicit function declaration, were NOT marked
obsolescent in C89/90 but are deleted in C99. Old-style (nonprototype)
declarations and definitions WERE marked obsolescent but NOT deleted.

- David.Thompson1 at worldnet.att.net
Mar 20 '06 #18

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
2785
by: Eric A. Forgy | last post by:
Hello, I am just learning Java and am trying to write a method that does something like //=========================================== public Static List find(double array,double val,String...
3
8034
by: rollasoc | last post by:
Hi, Having a slight problem with how to pass parameters to functions between threads. I have a form with a progress bar and a description label on it. It has a public function...
7
8476
by: The Crow | last post by:
code snippet below briefly shows what i need to do : public void Method1(params object args) { Method2(args); } public void Method2(params object args) { //Do something.
8
1537
by: Robert | last post by:
I am creating a small help browser. It is pretty much finished except I cannot find how to pass a file to it (i.e. browser.exe index.html, or any html file, and the html file opens in the browser)...
12
2662
by: Andrew Bullock | last post by:
Hi, I have two classes, A and B, B takes an A as an argument in its constructor: A a1 = new A(); B b = new B(a1);
3
2021
by: imtiazalikhan | last post by:
hi i am trying to passing arthematic expressions through command line arguments but i only get result of addition and multiplication cant get result of subtraction and division: ...
6
4812
by: unlikeablePorpoise | last post by:
I am trying to get JPype to pass a String into a Java class main function. Demonstration code below: =============JAVA============ package com; public class JPypeTest { public static void...
3
7904
by: H. Martins | last post by:
I need to use command line input to a tinny c# application: It goes like this: ** program.cs ** using System; using System.Collections.Generic;
4
5488
by: cjt22 | last post by:
Hi there. I just wondered whether anyone could recommend the correct way I should be passing command line parameters into my program. I am currently using the following code: def main(argv =...
0
7091
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7342
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6998
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7464
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5586
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5018
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4680
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3171
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1516
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.