Thread: how to solve this error msg

  1. #1
    Registered User
    Join Date
    Jan 2008
    Posts
    4

    how to solve this error msg

    Code:
    const int MAX = 15;
    int constructArray (int);
    
    
    int main ()
    {	
    	int array[MAX], size, n=0;
    	srand(time(NULL));
    	size = constructArray(array);
    
    }
    
    int constructArray (int a[])
    {
    	int i,size;
    	size = rand()%MAX;
    	for (i=0;i<size;i++)
    	{
    		a[i] = rand()%100;
    	}
    	return size;
    }
    i got this error msg "error: invalid conversion from " int*" to "int" at this line
    " size = constructArray(array); "

    can anyone tell me what is wrong and how to solve it?

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Your function prototype says that constructArray takes an int, but you're trying to give in an int[]. Your prototype needs to match reality -- in this case, reality is the actual function down below:
    Code:
    int constructArray (int a[]);

  3. #3
    Registered User
    Join Date
    Nov 2005
    Posts
    673
    umm just a thought. if you set the size variable to rand()&#37;MAX. then you will most likely only initialize some of the values not all of them.

  4. #4
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Yes, all the variables in the array won't be initialized, which is bad. You need to think of a solution.
    As for the prototypes, I suggest you match them exactly, including the actual name of the arguments, since some IDEs IntelliSense implementation takes the name of the arguments from the declarations.
    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.

  5. #5
    Registered User
    Join Date
    Nov 2005
    Posts
    673
    you may also like to put a more descriptive parameter name in the declaration of the function
    and a less descriptive one in the implementation. Doing so it will tell you more about the function with the intellisense code completion tool

  6. #6
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    a more descriptive parameter name in the declaration of the function
    and a less descriptive one in the implementation
    Inconsistencies between declaration and definition are generally bad, no matter what kind. Put the descriptive name everywhere. The code maintainers will thank you.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  7. #7
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by Raigne View Post
    you may also like to put a more descriptive parameter name in the declaration of the function
    and a less descriptive one in the implementation. Doing so it will tell you more about the function with the intellisense code completion tool
    That is absolutely nonsense. Some intellisense tools will read the declaration, some will read the definition and when you browse the definitions, you'll find less descriptive names even worse.
    And yet worse, you actually have to use those less descriptive names in your actual code. Even worse.
    No, take CornedBee's advice. Always use descriptive names everywhere.
    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.

  8. #8
    Registered User
    Join Date
    Nov 2005
    Posts
    673
    I am not trying to start an argument, but i believe all of us have reasonable points. I realize my method may be a little unusual, but nonetheless it works when used with the right IDE (MVC++2008). No im not saying my method is the best or if it is correct, but I don't think that it is
    That is absolutely nonsense.
    That quoted phrase is nonsense. I think it should be up to the original programmer to decide their method of writing code.
    I apologize for what may be considered as a flame. I just don't particularly enjoy being called stupid. Elysia you could of put your post in a more respectable manor.

    [EDIT]
    The reasoning for my saying that a less descriptive name in the implementation is so that (IF) you had to type the param name a lot you would not have to type as much.
    Last edited by Raigne; 02-08-2008 at 04:35 PM.

  9. #9
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by Raigne View Post
    I apologize for what may be considered as a flame. I just don't particularly enjoy being called stupid. Elysia you could of put your post in a more respectable manor.
    Please don't misunderstand. You aren't stupid. Your post was simply misguided. I may have used a too powerful word. If it makes you feel better, then I apologize.
    However, your method is not to recommend since it makes the code more difficult to read instead of helping it.
    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.

  10. #10
    Registered User
    Join Date
    Dec 2007
    Posts
    2,675
    Quote Originally Posted by Raigne View Post
    I think it should be up to the original programmer to decide their method of writing code.
    I strongly disagree. A good, considerate programmer will be thinking of the programmers who will follow him/her in maintaining the code and write code that documents what it's doing clearly, whether it's through the use of judicious commenting and/or code that is self-descriptive.

  11. #11
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    I don't disagree entirely with Raigne. Naturally, the rule of thumb should be descriptive names everywhere. I tend to follow that rule (despite the fact I find myself changing my names often as I come up with better ones).

    However, let's not forget function prototypes don't even need their arguments to be named. I've seen code where prototypes are simply declared with the types. I don't find this method entirely shocking.

    However, if anything the advise should have been the other way around, Raigne. That is, more descriptive names in the definitions, since that's where the code goes.
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  12. #12
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    Who doesn't simply copy the definition from the declaration or vice-versa anyway? This is one time where copy and paste is your friend!

    Of course D does it better...
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. replacement: please help me to solve this
    By zaohin in forum C++ Programming
    Replies: 4
    Last Post: 03-23-2009, 09:35 AM
  2. solve linear equation
    By unix7777 in forum C++ Programming
    Replies: 4
    Last Post: 11-12-2008, 11:47 PM
  3. Replies: 2
    Last Post: 04-25-2005, 11:59 AM
  4. ^^ help me solve the error
    By skwei81 in forum C++ Programming
    Replies: 2
    Last Post: 04-03-2003, 09:04 AM
  5. Help to solve this problem
    By Romashka in forum C++ Programming
    Replies: 3
    Last Post: 04-16-2002, 09:32 AM