This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
please help first timer.
- To: help-gcc at gnu dot org
- Subject: please help first timer.
- From: lev at apple dot com (Lloyd)
- Date: Mon, 25 Oct 1999 10:24:23 -0700
- Newsgroups: gnu.gcc.help
- Organization: apple
- Xref: wodc7nx0 gnu.gcc.help:1578
I have a small "read a random line from a file and print to std out" program
(below.) It works, compiles and all under 2.7.2.3 on Solaris 2.6
under 2.8 I get "warning: return type of `main' is not `int'"
and it dosen't work. if I compile on gcc 2.7.2.3 sol 2.6 it fails to run
prperly on the sol 2.6 gcc 2.8.0 machine. I don't even know where to start
looking.
Thanks
L.
/*
Random line from file
This program takes an argv[1] of a fully qualified file name.
And an argv[2] of the number of lines in the file.
A random line from this file is selected and dumped to stdout.
Program By Lloyd Vancil lev@apple.com 10-23-99
*/
/* Librarys */
# include <stdio.h>
# include <stdlib.h>
# include <string.h>
# include <time.h>
int rnd(int range);
int x;
void seedrnd(void);
int main(int argc, char *argv[] )
{ /* 2.8 complains at this line */
FILE *viewfile;
char buffer[512];
char nono1[] = "/etc/passwd";
char nono2[] = "/etc/shadow";
char nono3[] = "/etc/ptmp";
char nono4[] = "/etc/oshadow";
int result;
int count;
int maxl;
if(argc<3)
{
printf("I need a file and the number of items in the file, fella.\n");
printf("<!--exec cgi=\"/cgi-bin/Htmllist?filename+number\"-->\n");
return -1;
}
result = strcmp(argv[1],nono1);
if (result==0)
{
printf("File \"%s\" is a no-no.\n",argv[1]);
return -1;
}
result = strcmp(argv[1],nono2);
if (result==0)
{
printf("File \"%s\" is a no-no.\n",argv[1]);
return -1;
}
result = strcmp(argv[1],nono3);
if (result==0)
{
printf("File \"%s\" is a no-no.\n",argv[1]);
return -1;
}
result = strcmp(argv[1],nono4);
if (result==0)
{
printf("File \"%s\" is a no-no.\n",argv[1]);
return -1;
}
viewfile = fopen(argv[1],"r");
if (!viewfile)
{
printf("File \"%s\" is MIA.\n",argv[1]);
return -1;
}
if (!argv[2])
{
printf("I need a file and the number of lines in the file, fella.\n");
printf("<!--exec cgi=\"/cgi-bin/Htmllist?filename+number\"-->\n");
return -1;
}
maxl=atoi(argv[2]);
seedrnd();
x = rnd(maxl);
while(fgets(buffer,512,viewfile))
{
count++;
if (count == x){
printf(buffer);
}
}
return 0;
}
/*functions*/
int rnd(int range)
{
int r;
r=rand()%range+1;
return(r);
}
void seedrnd(void)
{
srand((unsigned)time(NULL));
}