Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > some more questions about argv

Reply
Thread Tools

some more questions about argv

 
 
Keith Thompson
Guest
Posts: n/a
 
      04-17-2005
Mark McIntyre <(E-Mail Removed)> writes:
> On Sat, 16 Apr 2005 23:26:20 GMT, in comp.lang.c , Keith Thompson
> <(E-Mail Removed)> wrote:

[...]
>>I'm sure you could do something equivalent to strcmp(), but since
>>strcmp() does *exactly* what's needed in this case, why bother?

>
> *shrug*


May I infer from that that there is no reason not to use strcmp() in
this case?

If you're in the habit of using strncmp() in cases where strcmp() is
simpler and more correct, I suggest that that's a bad habit.

[...]
>>I've thought about it, and it's almost certainly not what's wanted.

>
> You may well be right. I'm not particularly bothered tho, as it seems
> to me that this has descended into a yah-boo contest.


I'm not sure what you mean by that. Until now, I thought it was a
technical discussion about the correct way to implement a particular
piece of functionality in C.

>>I honestly don't understand what you're trying to say. Am I
>>missing something here?

>
> No idea. Look under the sofa I often find things under there I didn't
> even realise were missing.


I meant to ask whether I'm missing something meaningful in what you've
been saying. It appears I haven't, though I'd be glad to be
enlightened.

--
Keith Thompson (The_Other_Keith) http://www.velocityreviews.com/forums/(E-Mail Removed) <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.
 
Reply With Quote
 
 
 
 
William Ahern
Guest
Posts: n/a
 
      04-17-2005
Mark McIntyre <(E-Mail Removed)> wrote:
> On Fri, 15 Apr 2005 21:33:49 GMT, in comp.lang.c , Keith Thompson
> <(E-Mail Removed)> wrote:


> >Mark McIntyre <(E-Mail Removed)> writes:
> >> On 15 Apr 2005 06:19:48 -0700, in comp.lang.c , (E-Mail Removed)
> >> (Momo) wrote:
> >>
> >>>i have some code like :
> >>>char depend[] = "-depend";
> >>>if (argv[1] != depend)
> >>
> >> You can 't compare strings like that in C. Remember they're pointers
> >> to blocks of memory. All you did was compare the value of the
> >> pointers.
> >> You need strncmp.

> >
> >Why strncmp rather than strcmp?

>
> I learned long ago to always use the 'n' variants of string handlers
> for data input by users. Its become force of habit.


What's needed is something like

strlcmp(const char *, size_t, const char *, size_t)

 
Reply With Quote
 
 
 
 
Keith Thompson
Guest
Posts: n/a
 
      04-17-2005
William Ahern <william@wilbur.25thandClement.com> writes:
> Mark McIntyre <(E-Mail Removed)> wrote:
>> On Fri, 15 Apr 2005 21:33:49 GMT, in comp.lang.c , Keith Thompson
>> <(E-Mail Removed)> wrote:
>> >Mark McIntyre <(E-Mail Removed)> writes:
>> >> On 15 Apr 2005 06:19:48 -0700, in comp.lang.c , (E-Mail Removed)
>> >> (Momo) wrote:
>> >>
>> >>>i have some code like :
>> >>>char depend[] = "-depend";
>> >>>if (argv[1] != depend)
>> >>
>> >> You can 't compare strings like that in C. Remember they're pointers
>> >> to blocks of memory. All you did was compare the value of the
>> >> pointers.
>> >> You need strncmp.
>> >
>> >Why strncmp rather than strcmp?

>>
>> I learned long ago to always use the 'n' variants of string handlers
>> for data input by users. Its become force of habit.

>
> What's needed is something like
>
> strlcmp(const char *, size_t, const char *, size_t)


That might be useful, but does it solve some problem in this case that
strcmp() doesn't?

I'm assuming that the intent is to determine whether the string
pointed to by argv[1] is equal (in string comparison terms) to
"-depend". We can safely assume that both argv[1] and "-depend" are
properly nul-terminated strings.

strlcmp() might be useful if you want to match any of "-d", "-de",
"-dep", "-depe", "-depen", or "-depend", but I don't think that's what
the OP was looking for.

If you were making a general comment rather than trying to apply it to
this example, then never mind.

--
Keith Thompson (The_Other_Keith) (E-Mail Removed) <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.
 
Reply With Quote
 
Mark McIntyre
Guest
Posts: n/a
 
      04-17-2005
On Sun, 17 Apr 2005 00:41:42 GMT, in comp.lang.c , Keith Thompson
<(E-Mail Removed)> wrote:

>Mark McIntyre <(E-Mail Removed)> writes:
>> On Sat, 16 Apr 2005 23:26:20 GMT, in comp.lang.c , Keith Thompson
>> <(E-Mail Removed)> wrote:

>[...]
>>>I'm sure you could do something equivalent to strcmp(), but since
>>>strcmp() does *exactly* what's needed in this case, why bother?

>>
>> *shrug*

>
>May I infer from that that there is no reason not to use strcmp() in
>this case?


you may infer what you like, though mostly that I'm bored with the
discussion
>
>If you're in the habit of using strncmp() in cases where strcmp() is
>simpler and more correct,


I disagree that this is what I do.

>I suggest that that's a bad habit.


You're welcome to your opinion tho.


--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt>
 
Reply With Quote
 
 
 
Reply

Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
some more questions about argv Momo C Programming 2 04-16-2005 03:27 AM
int main(int argc, char *argv[] ) vs int main(int argc, char **argv ) Hal Styli C Programming 14 01-20-2004 10:00 PM
difference(s) between char** argv and char* argv[] David C Programming 10 09-15-2003 06:58 AM
char **argv vs. char* argv[] Bret C Programming 21 09-03-2003 03:24 AM
sys.argv[0] - 'module' object has no attribute 'argv' =?ISO-8859-1?Q?Thomas_N=FCcker?= Python 0 06-30-2003 02:07 PM



Advertisments