Solved

Simple C Code,

Posted on 2004-08-26
6
283 Views
Last Modified: 2010-04-15
hi experts,

I wrote a code in C as shown below and its giving the following error.
Cannot convert int* to int
Type mismatch in parameter1 in call to Junk(int,int)
Cannot convert int* to int
Type mismatch in parameter2 in call to Junk(int,int)

could anyone explain to me why this error? pls explain in a simple way, newbie here>)
#include<stdio.h>
#include<conio.h>
void junk(int,int);
void main()
{
int i=5,j=2;
junk(&i,&j);
printf ("\n%d%d",i,j);
}
void junk(int *i,int *j)
{

*i=*i**i;
*j=*j**j;
}
really appreciate the help
thanks in advance
deep
0
Comment
Question by:deepthiji
  • 4
  • 2
6 Comments
 
LVL 11

Expert Comment

by:avizit
ID: 11908745
in your functrion prototype you have


void junk(int,int);

while for your function definition you have


void junk(int *i,int *j)
{

*i=*i**i;
*j=*j**j;
}


so t hey dont match



0
 
LVL 11

Expert Comment

by:avizit
ID: 11908749
so you can just change the funtion prototype

from

void junk(int,int);

to

void junk(int *,int *);



0
 
LVL 3

Author Comment

by:deepthiji
ID: 11908761
sorrry i did not get that, As i said i just started learnning C,
>>in your functrion prototype you have
>>void junk(int,int);

>>while for your function definition you have
>>void junk(int *i,int *j)

what is wrong, should i declare void junk(int*,int*) at the bginning?
please explain some more,


0
Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 
LVL 11

Expert Comment

by:avizit
ID: 11908790
right ..


in the third line of your code it is the function prototype , here you tell the compiler what yuor function looks like i.,e what is its return type and what are its arguments

so you declare the function as

void junk(int,int);   i.e you say that the function named 'junk' retunrs no value and takes two integers as arguments.

but when you actuallky define the function you are defining it as

void junk(int *i,int *j)
{

*i=*i**i;
*j=*j**j;
}

i.e here you say that the function  returns  no value ( i.e void) and takes two pointer to integers (int *i, int *j)   as arguments

so you see your declaration and definition has a mismatch

thats why the error


>>>>
Cannot convert int* to int
Type mismatch in parameter1 in call to Junk(int,int)
Cannot convert int* to int
Type mismatch in parameter2 in call to Junk(int,int)
<<<<<


hence to correct it you should change the prototype to match the fucntion definition
so yuo can chnage the third line of your program

from

void junk(int,int);

to

void junk(int *,int *);




0
 
LVL 11

Accepted Solution

by:
avizit earned 500 total points
ID: 11908810
also your expressions look messy ,
it is advisable to use brackets  to make the meaning more clear

change

*i=*i**i;
*j=*j**j;

to

*i  =  (*i)  *  (*i);
*j  =  (*j)  *  (*j);

This way its more readable and easier to get the meaning at a glance
0
 
LVL 3

Author Comment

by:deepthiji
ID: 11908816
Got it, thanks a loot for the help,
thanks once again.
0

Featured Post

Why are Office 365 signatures so complicated?

Trying to setup transport rules for Office 365 email signatures and can’t quite figure it out? Having to test the signature over and over? Make things simple by using Exclaimer Cloud - Signatures for Office 365.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now