linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Martin Buchan <M.J.Buchan@gre.ac.uk>
To: linux-c-programming@vger.kernel.org
Subject: Re: warning: assignment makes integer from pointer without a cast
Date: Wed, 7 May 2003 16:44:42 +0100	[thread overview]
Message-ID: <20030507154442.GQ674@gre.ac.uk> (raw)

Hi,

Thanks to the list for the pointers.

On Tue, May 06, 2003 at 08:44:16PM +0100, Glynn Clements wrote:
> Martin Buchan wrote:
> 
> > I am trying to populate an array with strings which i have
> > extracted from another string using strtok. I have managed to split
> > up the string into its constituent parts but i cant seem to populate
> > the array. 
> 
> > static void item_response( GtkObject *passme )
> > { 	 /* Execute Apps */
> >    char *appArgs, *tmpappArgs, *token, *appCommand; 
> >    int pid, i = 0;
> >    char sep[] = " ";
> > 	
> >    int *numArgs = gtk_object_get_data(passme, "numargs_key"); /* Get number of arguments */
> >    char *nArgsPtr = malloc( *numArgs * sizeof (char) ); /* Create array of size numArgs */
> 
> This should be an array of pointers:
> 
>      char **nArgsPtr = malloc( *numArgs * sizeof (char *) ); /* Create array of size numArgs */
> 

I've ended up doing it a different way altogether as even with the
suggestions on here, i still couldn't get it to compile/run. (Even
after i had sorted *numArgs)

What i have instead which is cleaner i think is.

static void parse(buf, args)
	 char * buf;
    char **args;
{
	while (*buf != NULL) {
		/* Strip whitespace.  Use nulls, so that the previous argument 
		 * is terminated automatically. */
		while ((*buf == ' ') || (*buf == '\t'))    // || is OR
		  *buf++ = NULL;
		
		/* Save the argument. */
		*args++ = buf;
		
		/* Skip over the argument.  */
		while ((*buf != NULL) && (*buf != ' ') && (*buf != '\t'))
		  buf++;
	}
	*args = NULL;
}

static void item_response( GtkObject *passme )
{ /* Execute Apps */
	char *buf;
	char *args[64];
	
	buf = gtk_object_get_data(passme, "command_key"); /* assign my command and args to buf */
	parse(buf, args);
	
	execute(args); /* Here i call the execvp stuff with the properly sized array */
}

Thanks again
Martin



             reply	other threads:[~2003-05-07 15:44 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-05-07 15:44 Martin Buchan [this message]
2003-05-08 19:47 ` <time.h>: gmtime keeps giving the same time J.
  -- strict thread matches above, loose matches on Subject: below --
2003-05-06 13:57 warning: assignment makes integer from pointer without a cast Martin Buchan
2003-05-06 19:44 ` Glynn Clements

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20030507154442.GQ674@gre.ac.uk \
    --to=m.j.buchan@gre.ac.uk \
    --cc=linux-c-programming@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).