* Re: warning: assignment makes integer from pointer without a cast
@ 2003-05-07 15:44 Martin Buchan
2003-05-08 19:47 ` <time.h>: gmtime keeps giving the same time J.
0 siblings, 1 reply; 3+ messages in thread
From: Martin Buchan @ 2003-05-07 15:44 UTC (permalink / raw)
To: linux-c-programming
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
^ permalink raw reply [flat|nested] 3+ messages in thread
* <time.h>: gmtime keeps giving the same time ....
2003-05-07 15:44 warning: assignment makes integer from pointer without a cast Martin Buchan
@ 2003-05-08 19:47 ` J.
0 siblings, 0 replies; 3+ messages in thread
From: J. @ 2003-05-08 19:47 UTC (permalink / raw)
To: linux-c-programming
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.
^ permalink raw reply [flat|nested] 3+ messages in thread
* RE: <time.h>: gmtime keeps giving the same time ....
@ 2003-05-09 2:56 Ranga Reddy M - CTD ,Chennai.
0 siblings, 0 replies; 3+ messages in thread
From: Ranga Reddy M - CTD ,Chennai. @ 2003-05-09 2:56 UTC (permalink / raw)
To: J., linux-c-programming
Hi,
Here you are comparing the gmtime() output to The "date" command.
see the man pages of gmtime().This will give you the time in UTC format.
use localtime(). Gives same as your "date" output.
I have modified your code .Know it gives the
The code below.
#include <stdio.h>
#include <time.h>
int main(void) {
struct tm *tm_ptr;
time_t the_time;
(void)time(&the_time);
tm_ptr = localtime(&the_time);
printf("tm_ptr->tm_hour = %d\n", tm_ptr->tm_hour);
return 0;
}
Cheers
--------
Ranga Reddy M
-----Original Message-----
From: J. [mailto:mailing-lists@xs4all.nl]
Sent: Friday, May 09, 2003 1:17 AM
To: linux-c-programming@vger.kernel.org
Subject: <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.
-
To unsubscribe from this list: send the line "unsubscribe
linux-c-programming" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2003-05-09 2:56 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-05-07 15:44 warning: assignment makes integer from pointer without a cast Martin Buchan
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-09 2:56 Ranga Reddy M - CTD ,Chennai.
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).