compile a c program


 
Thread Tools Search this Thread
Top Forums Programming compile a c program
# 1  
Old 02-21-2008
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.
# 2  
Old 02-21-2008
Code:
/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
Code:
return 0;

# 3  
Old 02-21-2008
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.
# 4  
Old 02-21-2008
You probably need to get rid of the 'void' in front of the main() function. Try using int main()... or just main()...
# 5  
Old 02-22-2008
one more

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
# 6  
Old 02-22-2008
It was easier to rewrite this than to explain the problems.
Code:
/*
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;
}

# 7  
Old 02-22-2008
compile

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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

How to compile and run the ProC (*.pc) program?

Hi Team, I am very new to this forum and hope someone will help me in resolving the issue. I am new to Pro C also. I made some changes to the existing Pro C program and want to run the program with the changes. But I am unable to neither compile nor run the program. Please do the... (2 Replies)
Discussion started by: prakashs1218
2 Replies

2. UNIX and Linux Applications

Cannot compile/install gnu program

Hello, I'm trying to install ansifilter which is a program that translates ansi text to HTML. The idea is to install it on AIX 7.1 but is failing. All de appropriate gcc libraries and requirements for this software were installed successfully, but when I do the gmake I get the following... (4 Replies)
Discussion started by: bazajav
4 Replies

3. Programming

Not able to compile C program on z/OS (USS)

Hi, I having an issue while compiling a C program in USS (z/OS) machine. I was able to create objest files (.o) from source (.c) files but when I try to create a binary file from the object files I am getting the below error. $ cc util.o sock.o app.o -lnsl -o ptf FSUM3067 The archive... (7 Replies)
Discussion started by: madhu84
7 Replies

4. UNIX for Advanced & Expert Users

compile a c program in a encrypted way

Hi Guys, I wonder I had have a look to the cc compile options but I could be missing one but basically I'm compliling a c program where I will storing a command to connect to a database and also userid and password. The issue is that after the module is generated using a command like strings I... (14 Replies)
Discussion started by: arizah
14 Replies

5. Programming

compile a program in C with teradata sentences using cc

hi, I want to compile a program in C. It have a multiple calls to teradata. I have no idea how to compile in Aix. The compiler that I should be use is cc. I tried cc -G -KPIC tdsfbd0358.c this generates a tdsfbd0358.i and after I have no Idea what I have to make, a link? how?... (3 Replies)
Discussion started by: kajum
3 Replies

6. Programming

Compile c program on Sun Solaris OS

Can anyone tell me how to compile a c programs on SunSolaris OS 5.1 Version as gcc and cc are not working Thanks!!!! (4 Replies)
Discussion started by: shivu
4 Replies

7. BSD

How to compile a c program in freeBSD

Hi , I have freeBSD installed. I need to compile a c program which has embedded informix sql statement in it. Can you please help me to to do the same. I need to know what I should I do to make BSD compatable to compile the c program ? Thanks in advance Jisha (3 Replies)
Discussion started by: jisha
3 Replies

8. Programming

how to compile a program statically

how can i do static compilation in cc and -lldap i have system defined and user defined header file. Can any one suggest any site where from i can get some information about static and dynamic compilation. Thankx (1 Reply)
Discussion started by: bhakti
1 Replies

9. Programming

How to compile a c program by using gcc

Hi all, Yeasterday I try to compile c program by using cygwin. I just find an errors the fist one is concerinig about the end of the line. To summit my Assignment which is the day after tommorow I have to compile my c program by using just gcc. If any one know what do I have to... (5 Replies)
Discussion started by: Bell
5 Replies

10. Programming

how to compile a program

how do i go about compiling a simple hello world script in mandrake linux? this is something i have had no luck in finding on the main site, please help? thank you (2 Replies)
Discussion started by: CmpKillr
2 Replies
Login or Register to Ask a Question