Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | JohnF <john@please.see.sig.for.email.com> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: strange problem |
| Date | 2015-03-23 13:02 +0000 |
| Organization | PANIX Public Access Internet and UNIX, NYC |
| Message-ID | <mep2t3$7n6$1@reader1.panix.com> (permalink) |
| References | <mensmn$rrs$1@dont-email.me> <menvqm$sts$1@speranza.aioe.org> <meojc0$rrs$3@dont-email.me> |
bilsch <king621@comcast.net> wrote:
>> You could make it argc<=1, for example.
>
> I tried that just now. It doesn't fix the problem.
> This is truly a strange problem.
argc<2 is the usual test for no user-supplied command-line args.
But I've had problems with windows when the executable was in
a directory whose path contained spaces. Then the "pieces" of the
path were sometimes each counted as separate args (e.g., by mingw
compiler), and things got screwed up.
You have much debugging experience? The very first thing
I'd have tried immediately would've be
#include <stdio.h>
int main ( int argc, char *argv[] ) {
int iarg;
printf(" #args = %d\n", argc);
if ( argc > 0 )
for ( iarg=0; iarg<argc; iarg++ )
printf(" arg#%d = \"%.64s\"\n",
iarg, (argv[iarg]==NULL?"NULL":argv[iarg]) ); }
That ain't rocket science. So what happens?
To get around the windows problem described above,
I introduced the following kludge. You know how various
utilities use "--" to signal the end of command-line -switches?
I parsed my command-line args looking for a complementary "++"
to introduce command-line args. For example,
C:\silly directory name\with spaces\myprog.exe ++ arg1 arg2 etc
That way I knew for sure where args started. If no ++ in any
of the argc's, I assumed argc>1 meant argv[1],...,[argc-1]
were user input (and tough luck for the user if not).
So linux users didn't have to do that, but it would work if they did.
Maybe a bit more pain for users, but I couldn't figure
an easier way to robustly check.
--
John Forkosh ( mailto: j@f.com where j=john and f=forkosh )
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
strange problem bilsch <king621@comcast.net> - 2015-03-23 02:10 +0000
Re: strange problem Richard Heathfield <rjh@cpax.org.uk> - 2015-03-23 03:03 +0000
Re: strange problem Keith Thompson <kst-u@mib.org> - 2015-03-22 22:09 -0700
Re: strange problem Richard Heathfield <rjh@cpax.org.uk> - 2015-03-23 09:04 +0000
Re: strange problem bilsch <king621@comcast.net> - 2015-03-23 08:30 +0000
Re: strange problem Richard Heathfield <rjh@cpax.org.uk> - 2015-03-23 09:06 +0000
Re: strange problem bilsch <king621@comcast.net> - 2015-03-23 21:21 +0000
Re: strange problem Richard Heathfield <rjh@cpax.org.uk> - 2015-03-23 21:42 +0000
Re: strange problem bilsch <king621@comcast.net> - 2015-03-23 22:35 +0000
Re: strange problem Tim Rentsch <txr@alumni.caltech.edu> - 2015-03-24 12:20 -0700
Re: strange problem Keith Thompson <kst-u@mib.org> - 2015-03-23 15:23 -0700
Re: strange problem Richard Heathfield <rjh@cpax.org.uk> - 2015-03-23 23:14 +0000
Re: strange problem Keith Thompson <kst-u@mib.org> - 2015-03-23 17:10 -0700
Re: strange problem glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2015-03-23 03:03 +0000
Re: strange problem bilsch <king621@comcast.net> - 2015-03-23 08:37 +0000
Re: strange problem raltbos@xs4all.nl (Richard Bos) - 2015-03-23 09:37 +0000
Re: strange problem bilsch <king621@comcast.net> - 2015-03-23 21:27 +0000
Re: strange problem Richard Heathfield <rjh@cpax.org.uk> - 2015-03-23 21:43 +0000
Re: strange problem bilsch <king621@comcast.net> - 2015-03-23 22:36 +0000
Re: strange problem Keith Thompson <kst-u@mib.org> - 2015-03-23 17:09 -0700
Re: strange problem JohnF <john@please.see.sig.for.email.com> - 2015-03-23 13:02 +0000
Re: strange problem Richard Heathfield <rjh@cpax.org.uk> - 2015-03-23 13:10 +0000
Re: strange problem Robert Wessel <robertwessel2@yahoo.com> - 2015-03-23 19:18 -0500
Re: strange problem Richard Heathfield <rjh@cpax.org.uk> - 2015-03-24 00:28 +0000
Re: strange problem Robert Wessel <robertwessel2@yahoo.com> - 2015-03-23 19:38 -0500
Re: strange problem jt@toerring.de (Jens Thoms Toerring) - 2015-03-24 01:12 +0000
Re: strange problem Keith Thompson <kst-u@mib.org> - 2015-03-23 08:10 -0700
Re: strange problem Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2015-03-23 11:28 -0400
Re: strange problem bilsch <king621@comcast.net> - 2015-03-23 21:47 +0000
Re: strange problem Kaz Kylheku <kaz@kylheku.com> - 2015-03-23 21:53 +0000
Re: strange problem Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2015-03-23 18:34 -0400
Re: strange problem James Kuyper <jameskuyper@verizon.net> - 2015-03-23 18:58 -0400
Re: strange problem raltbos@xs4all.nl (Richard Bos) - 2015-03-23 09:54 +0000
Re: strange problem Kaz Kylheku <kaz@kylheku.com> - 2015-03-23 21:47 +0000
csiph-web