Thread: Error! Conflicting Types

  1. #1
    Registered User
    Join Date
    Nov 2008
    Posts
    22

    Error! Conflicting Types

    Hi everyone! last night i got a headache just because of this error "Conflicting Types". I try to play around with my code in hope that it gonna fix the problem, but seem useless. Here is my program:
    Code:
    /******************************************************************************/
    /******** This program is combines from Project #2 thru #5 to find the *******/
    /********** values that multiples of 7 or actually contain a digit 7 **********/
    /******************************************************************************/
    
    #include <stdio.h>
    #include <stdlib.h>
    #define MSIZE 500
    #define DSIZE 500
    
    int main()
    {
      int mul7[MSIZE];         //array multiples by 7
      int dig7[DSIZE];         //array contain a digit 7
      int n;                   //number
      int sr;                  //starting range
      int er;                  //engding range
      int c7;                  //values that multiples by 7
      int d7;                  //values that contain a digit 7
      double mavg;             //average of values multiples by 7
      double davg;             //average of values contain a digit 7
      
      printf("Enter start and end range values: ");
      while((n = scanf ("&#37;i %i", &sr, &er)) == 2)
           {
                if (sr < 0 || er > 999 || sr > er)
                     printf("Range value out of range\n");
                else
                {
                     c7 = fmul7(sr, er, mul7, MSIZE);
                     d7 = fdig7(sr, er, dig7, DSIZE);
                     mavg = calcavg(mul7, c7);
                     davg = calcavg(dig7, d7);
                     outresults(sr, er, mul7, MSIZE, dig7, DSIZE, c7, d7, mavg, davg);
                     printf("Enter start and end rage values: ");
                }
           }
      if (n != EOF)
           printf("Input error occurred in scanf\n");
      system("PAUSE");	
      return 0;
    }
    
    /******************************************************************************/
    /***** This little subprogram is about finding the values multiples by 7 ******/
    /******************************************************************************/
    
    int fmul7(int str, int endr, int mul7[], int m7size)
    {
      int ndx;         //index number
      int rem;         //remain number
      int i;           //count number
      
      i = 0;
      for (ndx = str; ndx <= endr; ndx++)
          {
               rem = ndx % 7;
               if (rem == 0)
                  {
                       mul7[m7size] = ndx;
                       i = i + 1;
                  }      
          }
          
      return 0;
    }
    
    /******************************************************************************/
    /**** this little subprogram is about finding the values contain a digit 7 ****/
    /******************************************************************************/
    
    int fdig7(int str, int endr, int dig7[], int d7size)
    {
      int q1;          //first digit
      int q2;          //second digit
      int q3;          //third digit
      int rem1;        //remainder
      int num;         //number
      int c7;          //count number
      
      c7 = 0;
      
      for(num = str; num <= endr; num++)
           {
                q1 = num / 100;
                rem1 = num - (q1 * 100);
                q2 = rem1 / 10;
                q3 = rem1 - (q1 * 10);
                if (q1 == 7 || q2 == 7 || q3 == 7)
                   {
                       dig7[d7size] = num;
                       c7++;
                   }
           }
      
      return 0;
    }
                  
    /******************************************************************************/
    /** This little subprogram is about finding the avarage of all number *********/
    /******************************************************************************/
    
    double calcavg(int md7[], int cntmd7)
    {
      int ndx;            //index number
      int sum;            //total sum
      double avg;         //total avarage
      
      sum = 0;
      avg = 0.0;
      
      for (ndx = 0; ndx < cntmd7; ndx++)
          sum = sum + md7[ndx];
      if (cntmd7 == 0)
          printf("Average divisor is zero - skip division \n");
      else
          avg = (double) sum / ndx;
          
      return 0;
    }
    
    /******************************************************************************/
    /************ This little subprogram is about output information **************/
    /******************************************************************************/
    
    void outresults (int sr, int er, int m7[], int szm7, int d7[], int szd7, int cm7,
                     int cd7, double mav, double dav)
    {
      int i;
      
      printf("Start Range = %i    End Range = %i\n", sr, er);
      printf("Multiple of 7 count is: %i\n", cm7);
      printf("Number having digit 7 count is: %i\n", cd7);
      printf("Multiple of 7 values are: \n");
      for (i = 0; i < cm7; i++)
          printf("%i\n", m7[i]);
      printf("Values having digit 7 are: \n");
      for (i = 0; i < cd7; i++)
          printf("%i\n", d7[i]);
      printf("Multiple of 7 average is: %0.2lf\n", mav);
      printf("Values having digit 7 average is: %0.2lf\n", dav);
    }
    I got error "coflicting types for 'calcavg', and conflicting types for 'outresults' "
    i'm having a hard time doing subprogram. I have tried to look at the C tutorial in this home website, but seem like the tutorials didn't cover the subprogram! so, i'm really not sure if i did this program right or not! hope somebody can help me out!
    Last edited by davewang; 12-05-2008 at 08:41 AM.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    What is the exact error message?

    EDIT:
    Right, the problem is that you failed to declare your functions before using them. Consequently, the implicit function declarations did not match with the function definitions (since arrays are not of the exact same type as pointers), hence the errors that you got.
    Last edited by laserlight; 12-05-2008 at 08:44 AM.

  3. #3
    Registered User
    Join Date
    Nov 2008
    Posts
    22
    I got error "coflicting types for 'calcavg', and conflicting types for 'outresults' "

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by davewang
    I got error "coflicting types for 'calcavg', and conflicting types for 'outresults' "
    As I mentioned in my edit, you should declare your functions before using them (i.e., use function prototypes).
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    You need to include some function prologues at the top, then everything will be fine.

    Code:
    double calcavg(int md7[], int cntmd7);
    void outresults (int sr, int er, int m7[], int szm7, int d7[], int szd7, int cm7,
                     int cd7, double mav, double dav);
    I think the compiler is treating some reference prior to the actual definition as the prologue, so you get "conflicting types".
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  6. #6
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Error 2 error C3861: 'fmul7': identifier not found g:\w00t\visual studio 2008\projects\temp\temp4.cpp 30
    Error 3 error C3861: 'fdig7': identifier not found g:\w00t\visual studio 2008\projects\temp\temp4.cpp 31
    Error 4 error C3861: 'calcavg': identifier not found g:\w00t\visual studio 2008\projects\temp\temp4.cpp 32
    Error 5 error C3861: 'calcavg': identifier not found g:\w00t\visual studio 2008\projects\temp\temp4.cpp 33
    Error 6 error C3861: 'outresults': identifier not found g:\w00t\visual studio 2008\projects\temp\temp4.cpp 34

    Your functions are missing prototypes as laserlight pointed out.

    Quote Originally Posted by MK27 View Post
    You need to include some function prologues at the top, then everything will be fine.

    Code:
    double calcavg(int md7[], int cntmd7);
    void outresults (int sr, int er, int m7[], int szm7, int d7[], int szd7, int cm7,
                     int cd7, double mav, double dav);
    I think the compiler is treating some reference prior to the actual definition as the prologue, so you get "conflicting types".
    The compiler treats all functions it cannot find prior to calls as
    Code:
    int function();
    (Note the missing "void" on purpose.)

    This silly behavior was removed in C99.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. invalid types 'int[int]' for array subscript
    By kolistivra in forum C++ Programming
    Replies: 6
    Last Post: 12-11-2010, 12:57 PM
  2. Generalising methods to handle multiple weapon types
    By Swarvy in forum Game Programming
    Replies: 2
    Last Post: 05-22-2009, 02:52 AM
  3. Replies: 6
    Last Post: 08-23-2008, 01:16 PM
  4. The Interactive Animation - my first released C program
    By ulillillia in forum A Brief History of Cprogramming.com
    Replies: 48
    Last Post: 05-10-2007, 02:25 AM
  5. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM