Skip to contentSkip to conversation

warning: assignment makes integer from pointer without a cast

DISCUSSION Martin Buchan 2 participants 2 messages May 7, 2003 – May 8, 2003

lore
Share & tools
lore
#0 lore raw

Hi,

Thanks to the list for the pointers.

Quoted 13 lines · Glynn Clements
Quoted 11 lines · Martin Buchan

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[] = " ";
Quoted 7 lines
Quoted 2 lines

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

#1 lore raw

<time.h>: gmtime keeps giving the same time ....

Hello,

Output from the date command in my terminal:
Thu May 8 21:42:28 CEST 2003

Output from my `problem'_program.c
19

#include <stdio.h>
#include <time.h>

int main(void) {
struct tm *tm_ptr;
time_t the_time;

(void)time(&the_time);
tm_ptr = gmtime(&the_time);

printf("tm_ptr->tm_hour = %d\n", tm_ptr->tm_hour);

return 0;
}

No matter what I do, this C - code keeps giving me as output 19.

Is my system messed up or my head ?

Any thoughts are more than welcome

Thnkx....

J.