Hi guys:

I got a program from a developer. My main problem is that the code is in C and I been trying to compile it, but it keeps me giving errors, well mainly warning, but some of them I am not sure what they mean and/or how to fix them. Here is what I get get from the compile. The codes that are in bold are the ones I am having problems with. I can send you the files that are related to the errors if you need them, but since they are many and maybe some of the problems are common I have not include them here. I appreciate the help,

Gus

% ./install.csh >> read.list
[B]max.c: In function 'max':
max.c:115: warning: too few arguments for format[/B]
[B]newbincross2.c: In function 'main':
newbincross2.c:191: warning: format '%i' expects type 'int', but argument 3 has type 'long int'
newbincross2.c:191: warning: format '%i' expects type 'int', but argument 5 has type 'long int'[/B]
ludcmp.c: In function 'ludcmp':
ludcmp.c:16: warning: incompatible implicit declaration of built-in function 'malloc'
[B]get_index.c: In function 'get_index':
get_index.c:13: warning: incompatible implicit declaration of built-in function 'strlen'[/B]
get_index.c: In function 'get_index':
get_index.c:13: warning: incompatible implicit declaration of built-in function 'strlen'
get_index.c: In function 'get_index':
get_index.c:13: warning: incompatible implicit declaration of built-in function 'strlen'
get_index.c: In function 'get_index':
get_index.c:13: warning: incompatible implicit declaration of built-in function 'strlen'
main.c: In function 'main':
main.c:72: warning: incompatible implicit declaration of built-in function 'malloc'
main.c:72: warning: incompatible implicit declaration of built-in function 'exit'
main.c:77: warning: incompatible implicit declaration of built-in function 'exit'
rm: No match.
[B]hist2.c: In function 'main':
hist2.c:39: warning: format not a string literal and no format argument[/B]s
hist2.c:41: warning: format not a string literal and no format arguments
hist2.c:49: warning: incompatible implicit declaration of built-in function 'exit'
hist2.c:101: warning: incompatible implicit declaration of built-in function 'malloc'
utilities.c: In function 'allocate':
utilities.c:100: warning: incompatible implicit declaration of built-in function 'malloc'
gcardonav@roam-167-232.bgsu.edu%

Compilers like to puke out a lot of errors for the same line. And an error on one line can spew out a lot of errors on other succeeding lines. So in practice I generally fix the error at the top of the list then recompile to get a new list of errors.

>> warning: format '%i' expects type 'int',
Look at the format specifications and you will probably find that you need to use %ld for long int.

>>warning: incompatible implicit declaration of built-in function 'malloc'
Most likely you forgot to include a header file.

Thanks I was able to correct those errors. The next one comes from the following code

#include<stdio.h>
#include<math.h>
#include<malloc.h>
#include<stdlib.h>


int get_index(char *s1,char *s2)
{

 int  i,n,n2,pos;


 n=strlen(s1);
 n2=strlen(s2);
 pos=-1;

 for(i=n-n2;i>-1;i--) 
 {
  if(!(strncmp(&s1[i],s2,n2))) 
  {
   pos=i;
   break;
  }
	   
 }


 return pos;
}

The error is the following

get_index.c: In function ‘get_index’:
get_index.c:13: warning: incompatible implicit declaration of built-in function ‘strlen’
get_index.c: In function ‘get_index’:
get_index.c:13: warning: incompatible implicit declaration of built-in function ‘strlen’
get_index.c: In function ‘get_index’:
get_index.c:13: warning: incompatible implicit declaration of built-in function ‘strlen’
get_index.c: In function ‘get_index’:
get_index.c:13: warning: incompatible implicit declaration of built-in function ‘strlen’

Any idea how's this error happening ?

Gus

same problem as I mentioned before -- you forgot to include a header file, in this case it was string.h. You can't call functions if they have not been previously declared.

Wow and here I thought it was a problem with the declaration. My next problem is the following

max.c: In function ‘max’:
max.c:115: warning: too few arguments for format

which it comes out of this file.

Any idea ?

#include<stdio.h>
#include<math.h>
#include<malloc.h>
#include<stdlib.h>

#include "types.h"

object *max(DATA_TYPE *image,DATA_TYPE thresh,int mesh,DATA_TYPE rad11,DATA_TYPE rad22)
{

 int       i,j,m2,k,l,test,nb_obj,buff_obj,buff_obj0;
 int       *index;
 DATA_TYPE *temp,pix0;
 CENT_TYPE x,y;
 FILE      *file;
 object    *obj,*objlist;
 double    bg,sigma,rad1,rad2;
 
 rad1=rad11;
 rad2=rad22;
 ADU_EL=1.0;





 m2=stack_width+2;
 buff_obj0=1000;
 buff_obj=buff_obj0;
 if(!(obj=(object *)malloc(buff_obj0*sizeof(object)))) 
   printf("Malloc error at local_max\n");
 
  nb_obj=0;



  for(i=m2;i<width-m2;i++)
   for(j=m2;j<height-m2;j++)
    {

     pix0=image[i+width*j];

      if(pix0>thresh && pix0<saturation && pix0>pix_min)
      {
          test=1;
          for(k=-mesh;k<=mesh;k++)
           for(l=-mesh;l<=mesh;l++)
	   {
	     if(image[i+k+width*(j+l)]>pix0) {test=0; break;}
           }


	  if(test) 
	  {
           for(k=-mesh2;k<=mesh2;k++)
            for(l=-mesh2;l<=mesh2;l++)
	    {
	     if(image[i+k+width*(j+l)]>pix0 || image[i+k+width*(j+l)]<pix_min) {test=0;}
            }
	  }
 
           if(test) 
	   { 
             if(nb_obj>buff_obj-1)
             {
              buff_obj += buff_obj0;
              if(!(obj=(object *)realloc(obj,buff_obj*sizeof(object))))
              printf("Realloc error at local_max\n");
             }
	     bg=background(i,j,image,&sigma);
            if(sigma>0.0001)
	    {
             cent(i,j,&x,&y,image);

             obj[nb_obj].x=x;
             obj[nb_obj].y=y;
             obj[nb_obj].xi=i;
             obj[nb_obj].yi=j;
             obj[nb_obj].bg=bg;

             obj[nb_obj].sigma=sigma;
             obj[nb_obj].pixmax=pix0-bg;
             ++nb_obj;
	    }

          }
      }
    }

printf("nb_obj: %i %i\n",nb_obj,NSTARS);

  temp = (DATA_TYPE *)malloc(nb_obj*sizeof(DATA_TYPE));

  index = (int *)malloc(nb_obj*sizeof(int));

  for(i=0;i<nb_obj;i++) temp[i]=obj[i].pixmax;
  quick_sort(temp,index,nb_obj);

   nnstars=nb_obj;
   if(nnstars>NSTARS_MAX) nnstars=NSTARS_MAX;
  objlist = (object *)malloc(nnstars*sizeof(object));




  for(i=0;i<nnstars;i++)
  {
    objlist[i]=obj[index[nb_obj-i-1]];
    aperphot(&objlist[i],image);
  }


  free(obj);    
  free(temp);
  free(index);

 return objlist;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.