functions

J

Jim Madcoy

code
void fun1(int a[]){
input a
}
void fun2(int b[]){
output b
}
int main(){
int a[1000]
fun1(a);
fun2(a);
return 0;
}

Can u tell why my progrm don't output array?

Thank u

JM
 
E

E. Robert Tisdale

Jim said:
code
void fun1(int a[]){
input a
}
void fun2(int b[]){
output b
}
int main(){
int a[1000]
fun1(a);
fun2(a);
return 0;
}

Can u tell why my progrm don't output array?

Try to compile it.
Your compiler will tell you what's wrong.
 
E

Eric Sosman

Jim said:
code
void fun1(int a[]){
input a
}
void fun2(int b[]){
output b
}
int main(){
int a[1000]
fun1(a);
fun2(a);
return 0;
}

Can u tell why my progrm don't output array?

Because your code bears the same resemblance
to C that your question does to English. Try
providing actual code next time. (Oh, sorry,
let me rephrase that: tri pstnig reel cod nxt
time d00d dont mes witn pair afrazez)
 
W

Walter Roberson

:code
:void fun1(int a[]){
:input a
:}
:void fun2(int b[]){
:eek:utput b
:}
:int main(){
:int a[1000]
:fun1(a);
:fun2(a);
:return 0;
:}

:Can u tell why my progrm don't output array?

You cross-posted this in comp.lang.c++ and comp.lang.c, so you
must be expecting answers that relate to each of the languages.

I will leave the C++ answer to others.

In the case of C, there is no type or keyword or operator named
'input' or 'output', so the reason that the program will not output
an array is that the program would not compile at all.
 
H

Howard

Jim Madcoy said:
code
void fun1(int a[]){
input a
}
void fun2(int b[]){
output b
}
int main(){
int a[1000]
fun1(a);
fun2(a);
return 0;
}

Can u tell why my progrm don't output array?

Thank u

JM

Why are you posting to both the C and C++ newsgroups? You do know they're
not the same language, don't you?

Without real, compileable code, and an explanation of what *does* happen
when you run it, who can say? As it is, it won't even compile. Show the
code where you've put "input a" and "output b", and maybe we can answer.
(Also, pick a language, either C or C++, and post to the correct group.)

-Howard
 
F

Fred L. Kleinschmidt

Jim said:
code
void fun1(int a[]){
input a
}
void fun2(int b[]){
output b
}
int main(){
int a[1000]
fun1(a);
fun2(a);
return 0;
}

Can u tell why my progrm don't output array?

Thank u

JM

Who knows? Do we have to guess what you mean by "input a" and "output
b"?
Also, how do you expect functions fun1 and fun2 to determine the size of
the array?
 
M

Martijn Mulder

Jim Madcoy said:
code
void fun1(int a[]){
input a
}
void fun2(int b[]){
output b
}
int main(){
int a[1000]
fun1(a);
fun2(a);
return 0;
}

Can u tell why my progrm don't output array?

Thank u

JM

#include<iostream>
#include<algorithm>
void fun1(int a[]){
for(int b=0;b<1000;b++)a=b;
}
void fun2(int b[]){
copy(&b[0],&b[1000],ostream_iterator<int>(cout,","));
}
int main(){
int a[1000];
fun1(a);
fun2(a);
return 0;
}
 
D

DHOLLINGSWORTH2

Jim Madcoy said:
code
void fun1(int a[]){
input a
}
void fun2(int b[]){
output b
}
int main(){
int a[1000]
fun1(a);
fun2(a);
return 0;
}

Can u tell why my progrm don't output array?

Thank u

JM

You should be aware that b above is a pointer to a list of integers, you
should also be aware that "output b" is not a part of any programming
language that I'm familiar with, if it were your output would be the address
of the first element in that list.
 
T

Thomas Matthews

Jim said:
code
void fun1(int a[]){
input a
}
void fun2(int b[]){
output b
}
int main(){
int a[1000]
fun1(a);
fun2(a);
return 0;
}

Can u tell why my progrm don't output array?

Thank u

JM
Here are some obvious points:
1. The array elements are not initialized.
"input a" is invalid syntax.

2. You should pass another parameter along with the
array to indicate the number of elements in the
array:
void input_array(int * array,
unsigned int array_size);

3. The Languages C and C++ do not have statements
to output or input an array as a single entity.
You will have to iterate over each member.
void output_array(int * array,
unsigned int elems_to_output)
{
unsigned int i;
for (i = 0; i < elems_to_output; ++i)
{
#ifdef __cplusplus__
std::cout << array << std::endl;
#else
printf("%d\n", array);
#endif
}
return;
}

4. The C++ language provides some iteration help
in the STL. You might also use a std::vector
instead of an array.

5. Decide which language you are using, C or C++.
The example above shows just one of the differences
between the two languages.

--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.comeaucomputing.com/learn/faq/
Other sites:
http://www.josuttis.com -- C++ STL Library book
http://www.sgi.com/tech/stl -- Standard Template Library
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,201
Messages
2,571,049
Members
47,655
Latest member
eizareri

Latest Threads

Top