compile a c program

I am trying to compile a c program on AIX 5.3L 64-bit unix.

I have used this program in the past and it works.

Does anybody know what this error means?

/usr/local/bin> gcc get_epoch_secs.c get_epoch_secs

gcc: get_epoch_secs: No such file or directory
get_epoch_secs.c: In function 'main':
get_epoch_secs.c:13: warning: return type of 'main' is not 'int'

thanks.

/usr/local/bin> gcc get_epoch_secs.c -o get_epoch_secs

And on line 13 of main() in your code you have a return statement - it should read

return 0;

Ok, no matter where it put it I get the same reply.

/*
Listing 5 get_epoch_secs.c
get_epoch_secs.c
return the number of seconds from the Epoch
*/
#include <stdio.h>
#include <time.h>

void main(argc, argv)
int argc;
char **argv;
{
time_t tloc;

printf("%ld", time(&tloc));
}

Where should it go?

thanks.

You probably need to get rid of the 'void' in front of the main() function. Try using int main()... or just main()...

One more compile. I have not worked with these programs in a couple of years. This is is giving the error below. If I change to

main
int main
void main

it does not seem to help.

"get_date_from_secs.c" 44 lines, 834 characters
/*
Listing 6 get_date_from_secs.c
get_date_from_secs.c
pass the number of seconds since
the Epoch, and return a Gregorian
date argument
use "%02d" date format.

*/
#include <stdio.h>
#include <time.h>
#include <stdlib.h>

int main(int argc, char **argv)
{
char *secarg;
struct tm rettm;
time_t now;

/* grab the first argument, time in seconds */
if((secarg = ++argv) == NULL)
{ /
error /
printf("-1");
exit(1);
}
else
{
if((now=atol(secarg)) == NULL)
{ /
error */
printf("-2");
exit(1);
}
else
{
rettm=*localtime(&now);
/printf("%s", asctime(&rettm));/
/printf("%2d/%d/%d", rettm.tm_mon+1, rettm.tm_mday, rettm.tm_year+1900);/
printf("%02d%02d%02d%02d", rettm.tm_mon+1, rettm.tm_mday, rettm.tm_hour, rettm.tm_min);

/usr/local/bin> gcc get_date_from_secs.c -o get_date_from_secs
get_date_from_secs.c: In function 'main':
get_date_from_secs.c:28: warning: comparison between pointer and integer

It was easier to rewrite this than to explain the problems.

/*
Listing 6 get_date_from_secs.c
get_date_from_secs.c
pass the number of seconds since
the Epoch, and return a Gregorian
date argument
use "%02d" date format.

*/
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#include <errno.h>

int main(int argc, char **argv)
{
	struct tm *rettm;  /* use a pointer */
	time_t now=time(NULL);  /* add a value to now */
	char timebuf[128]={0x0}; /* place to park date time values */

	/* grab the first argument, time in seconds Note:  will segfault the old way*/
	if(argc < 2)   /* argc has to be > 1 */
	{ /* error */
		fprintf(stderr, "bad arguments -1\n"); /* you can also user perror() here */
		exit(1);
	}
	/* zero is a valid number and is valid for epoch seconds */
	errno=0;  /* set errno to a known state */
	if((now=atol(argv[1])) == 0 && errno !=0) /* atol never returns a NULL use argv */
	{ /* error */
	  /* you get to add errno checking here */
		fprintf(stderr,"invalid conversion -2\n"); /* you can also user perror() here */
		exit(1);
	}
	rettm=localtime(&now);  /* you can check for a NULL return here if you want */
	/* check your man page - some implementations only allow struct tm > Dec 13 20:45:52 UTC 1901. */
	/* use std library for time/date  use strftime */

	printf("%02d%02d%02d%02d\n", rettm->tm_mon+1, rettm->tm_mday, rettm->tm_hour, rettm->tm_min);
	strftime(timebuf, sizeof(timebuf),"%m %d %H %M %S", rettm);
	printf("%s\n", timebuf);

    return 0;
}

Thank you!

I have not used these for 2-3 years.

I call them from a shell script that gets the last trace file and sends me the first 100 lines.

/usr/local/bin> xsecs=$(get_epoch_secs)
/usr/local/bin> thedate=$(get_date_from_secs $((xsecs-3900)))
/usr/local/bin> echo $thedate
02220942 02 22 09 42 08

Your return is giving me 02220942 02 22 09 42 08

the touch is create the file and these as directories "02 22 09 42 08"

I only want it to return 65 minutes ago, i.e 02220942

then the touch is $touch 02220942 file_name
not $touch 02220942 02 22 09 42 08 file_name

I am trying to change the return, but how do I get rid of the " 02 22 09 42 08"?

I got it by changing this :

printf\("%02d%02d%02d%02d\\n", rettm-&gt;tm_mon\+1, rettm-&gt;tm_mday, rettm-&gt;tm_hour, rettm-&gt;tm_min\);
strftime\(timebuf, sizeof\(timebuf\),"%m %d %H %M %S", rettm\);
/*printf\("%s\\n", timebuf\); */

Don't ask me what I did!

thanks!!!