GIDForums  

Go Back   GIDForums > Computer Programming Forums > C Programming Language
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 26-Jul-2005, 22:07
likeit likeit is offline
New Member
 
Join Date: Jul 2005
Posts: 11
likeit is on a distinguished road

passing parameter


i have a prog by input a number then after press ENTER the output is value of the number.if the number 0 then exit the prog
output:

input a number: 4
value:4

CPP / C++ / C Code:
#include<stdio.h>
#include<conio.h>

int view(int );
void printview(int a);
main(){
int no,view;
do{
printf("input a number:");
scanf("%d",&no);
view=view(no);
printview(view);
}while(no!=0);
getch();
return 0;
}

int view(int a)
{
a=no;
return a;
}

void printview(int a)
{
printf("value:%d",a);
}

but as i get the result,the passing doesn't work.

what cause the passing parameter can't run?
  #2  
Old 26-Jul-2005, 23:34
nkhambal nkhambal is offline
Regular Member
 
Join Date: Jul 2004
Location: CA USA
Posts: 313
nkhambal is a jewel in the roughnkhambal is a jewel in the rough
were you able to complie it ? I see one mistake in function view()

CPP / C++ / C Code:
int view(int a)
{
a=no;
return a;
}

where does this variable "no" come from.? Its not declared inside view() and the one in main() is local to main() and not global. Hence you can not access it inside. You are trying to assign a non-existent variables value to variable a.


My guess is ( sorry, if its not as good as yours ;-) ), this is what you intended to write,

CPP / C++ / C Code:
int view(int a)
{
int no=a;
return no;
}

Thanks,
  #3  
Old 27-Jul-2005, 05:53
alcedo's Avatar
alcedo alcedo is offline
Member
 
Join Date: Jul 2005
Location: Singapore
Posts: 198
alcedo will become famous soon enough
CPP / C++ / C Code:
int view(int a)
{
   return a;
}

I suppose that would work too
__________________
People should read the rules and regulation before posting!

The Best is yet to be...
  #4  
Old 27-Jul-2005, 05:57
alcedo's Avatar
alcedo alcedo is offline
Member
 
Join Date: Jul 2005
Location: Singapore
Posts: 198
alcedo will become famous soon enough
Ar actually, i think you are confused over functions parameter passing
CPP / C++ / C Code:
int view(int no)    //U can declare your function like this as well.
{
   return no;
}

void printview(int no)
{
   printf("value:%d",no);
}

in short, U dont have to match parameter names exactly. U dont have to return a value labelled as 'a' to a function that has 'a' as its parameter declaration.
__________________
People should read the rules and regulation before posting!

The Best is yet to be...
  #5  
Old 27-Jul-2005, 08:33
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 4,793
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold
Quote:
Originally Posted by likeit
i have a prog by input a number



but as i get the result,the passing doesn't work.


There are several bugs in the code that you posted that prevent the code from compiling on anything that I can imagine. They are fatal, guaranteed-not-to-compile-with-any-compiler bugs.

1. If the code that you posted is not exactly the code that you compiled, then no one can help you understand your problem. Paste your code into the message; don't retype.

2. If the code that you posted is exactly the code that you compiled, please tell us what compiler you used. (We still may be able to help you, but I would like to know this.) When you say "the passing didn't work" you should tell us exactly what you got, and why you think it should have been something else.

3. If your code didn't compile, then look at the compiler's error messages. Fix the code so that it compiles. If you can't figure out what the error messages mean, then post the error messages exactly as the compiler gave them to you (paste the exact error message; don't summarize). Maybe we can point out how to interpret the compiler's error messages, so that you can understand what it's trying to tell you.

Regards,

Dave
 
 

Recent GIDBlogPython ebook by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Trouble passing STL into a function Clive73 C++ Forum 5 10-May-2005 19:00
Finding the memory address of a pass-by-reference parameter? ScottLewis C++ Forum 1 30-Apr-2005 12:13
parameter passing? jheron C++ Forum 15 02-Mar-2005 06:04
Passing referance and passing pointer Poolan C++ Forum 6 29-Oct-2004 08:18
cannot convert parameter error on DrawTextA ozzytx MS Visual C++ / MFC Forum 1 22-Sep-2004 03:45

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 11:55.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.