• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: problems working it out.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: problems working it out.


  • Subject: Re: problems working it out.
  • From: Thaddeus Cooper <email@hidden>
  • Date: Fri, 17 Jun 2005 11:06:04 -0700

Ummm probably the wrong group to post this too, but hey.

I don't parse command line arguments by hand anymore. I usually use something like getopt which does the work for me and gets me out of the complexities of doing this kind of thing. That said, I think the solution to your problem is the following:

The string you are trying to parse is "TEST=-YES"

Assuming that the whole thing is in argv[2] then what you really want to do is something like this:

#include <stdio.h>
#include <strings.h>

main(argc, argv)
int argc;
char **argv;
{
char *ptr;
char tmp[80];

strcpy(tmp, argv[2]);
ptr = index(tmp, '=');
ptr++;
if (strcmp(ptr, "-YES") == 0) {
/* equal continue processing */
printf("yes\n");
}
}

I checked that this actually works. :-)

--Thaddeus O. (Nice-to-flex-my-C-programming-once-in-a-while) Cooper
(email@hidden)

On Jun 17, 2005, at 10:30 AM, D. Walsh wrote:

I've got the following routine I was trying to make dynamic but because my programming knowledge is as good as most I've run into a brick wall.

Here's my routine

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

  bool match = false;

  if (argc == 4) {
    if (strncmp("TEST=-YES", buffer, strlen("TEST=-YES"))) {


Here's what I'm trying to achieve, argv[2] holds the string in question I want to test

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

  bool match = false;

  if (argc == 4) {
    if (strncmp(argv["=-YES", buffer, strlen(argv["=-YES"))) {


but obviously this is wrong.


Can someone with better knowledge show me what would be correct please?

-- Dale
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >problems working it out. (From: "D. Walsh" <email@hidden>)

  • Prev by Date: multiple executables, one application
  • Next by Date: Re: GCC Warning Options
  • Previous by thread: Re: problems working it out.
  • Next by thread: cstdlib include compile errors GCC 4.0
  • Index(es):
    • Date
    • Thread