arrays incomplete function call

R

rohit

main()
{

int i;
int marks[] = {55,65,75,56,78,90};

for (i = 0; i <= 6; i++)
disp(&marks);
}

disp(int *n)

{

show (&n);
}
 
P

pemo

rohit said:
main()
{

int i;
int marks[] = {55,65,75,56,78,90};

for (i = 0; i <= 6; i++)
disp(&marks);
}

disp(int *n)

{

show (&n);
}


void disp(int *n)
{
printf("%d\n", *n);
}


int main(void)
{

int i;
int marks[] = {55,65,75,56,78,90};

for (i = 0; i <= 6; i++)
disp(&marks);

return 0;
}
 
M

Micah Cowan

rohit said:
main()
{

int i;
int marks[] = {55,65,75,56,78,90};

for (i = 0; i <= 6; i++)
disp(&marks);
}

disp(int *n)

{

show (&n);
}


1. Why do you need show() at all? Why not write the implementation
directly into disp?

2. You should pass in the number of elements in the array as well. If
this is homework and they don't allow you to change the function
prototype, I guess you'd have to hard-code it (but that's a bad
idea).

3. Use printf() in a for loop to do what you want. Now go read up on 'em!
 
P

Pedro Graca

rohit said:

int main(void) is better because
a) it works for C90 and C99
b) you're documenting the fact that main() doesn't use any parameters
{
int i;
int marks[] = {55,65,75,56,78,90};

`marks' has 6 elements ...
for (i = 0; i <= 6; i++)

but this for() loop will execute 7 times.
disp(&marks);


No prototype for disp() in scope.
And you should return something from main().

return 0;
}

disp(int *n)
{
show (&n);

Why do you need to call another function to show the value of `n'?
And if you really do (because you'll use that function from somewhere
else in your code?) wouldn't it be better to pass the plain value and
not it's address?

Assuming your code is what you really want, the prototype for show()
should be something similar to

void show(int **n);
 
A

August Karlstrom

rohit said:
main()
{

int i;
int marks[] = {55,65,75,56,78,90};

for (i = 0; i <= 6; i++)
disp(&marks);
}

disp(int *n)

{

show (&n);
}


You recently started the thread "i++ * i++". Note that it's considered
common courtesy to reply if you get good advice before you go on with
your next question.


Thank you,

August
 
Y

yuhua_stone

main()
{
int i;
int marks[] = {55,65,75,56,78,90};
for (i = 0; i < 6; i++)
disp(&marks);
}
disp(int *n)
{
show (&n);
}
/* you can write show() like this: */
show(int **p)
{
printf("%d\t",**p);
}
 
V

Vladimir S. Oka


int main(void)
{
int i;
int marks[] = {55,65,75,56,78,90};
for (i = 0; i < 6; i++)
disp(&marks);


Error: no prototype in scope for `disp()`
}
disp(int *n)
{
show (&n);

Error: no prototype in scope for `show()`
}
/* you can write show() like this: */
show(int **p)
{
printf("%d\t",**p);

Error: no prototype in scope for `printf()`

If you don't (eventually) terminate this with '\n', you may not get any
output whatsoever.

So, what was your question? Were you replying to someone? What have you
been replying to? Why didn't you check that your reply was correct?

See <http://cfaj.freeshell.org/google/> and
<http://clc-wiki.net/wiki/Introduction_to_comp.lang.c> before posting
here again.
 
G

Guest

/* you can write show() like this: */
void show(int **p)
{
printf("%d\t",**p);
}

void disp(int *n)
{
show (&n);
}

void main( )
{
int i;
int marks[] = {55,65,75,56,78,90};
for (i = 0; i < 6; i++)
disp(&marks);
}



/* nothing to do */
 
R

Richard Heathfield

???c said:
/* you can write show() like this: */
void show(int **p)
{
printf("%d\t",**p);

Undefined behaviour - use of variadic function without valid function
prototype in scope.
}

void disp(int *n)
{
show (&n);
}

void main( )

Undefined behaviour - violation of interface specification for main.
 
G

Guest

#include<stdio.h>

int show(int **p); /*function protype 1*/
int disp(int *n); /*function protype 2*/

int main( )
{ int i;
int marks[] = {55,65,75,56,78,90};
for (i = 0; i < 6; i++)
disp(&marks);
return 1;
}

int disp(int *n)
{ show (&n);
return 0;
}

/* you can write show( ) like this: */
int show(int **p)
{ printf("%d\t",**p);
return 0;
}

/*now,what's wrong with it?*/
 
J

jaysome

雨花石c said:
#include<stdio.h>

int show(int **p); /*function protype 1*/
int disp(int *n); /*function protype 2*/

int main( )

Change that to:

int main(void)
{ int i;
int marks[] = {55,65,75,56,78,90};
for (i = 0; i < 6; i++)
disp(&marks);
return 1;


The only values you can return from main() if you are to conform to the
C standard are 0, EXIT_SUCCESS and EXIT_FAILURE. The latter two are
macros defined in <stdlib.h>. Returning 0 results in the same behavior
as returning EXIT_SUCCESS.

It's interesting to note that although returning 0 is equivalent to
returning EXIT_SUCCESS, the C standard does not mandate that
EXIT_SUCCESS evaluate to an integer value of 0. The C standard only
requires that the EXIT_SUCCESS macro expands to an integer constant
expression. Thus, a conforming implementation could have the following
defines in <stdlib.h>:

#define EXIT_SUCCESS 3
#define EXIT_FAILURE -1

The code snippet that handles the return value from main() in such a
hypothetical implementation could look something similar to this:

if ( (return_value == 0) || (return_value == EXIT_SUCCESS) )
{
/* return an implementation-defined form of
the status successful termination.
*/
}
else if ( return_value == EXIT_FAILURE )
{
/* return an implementation-defined form of
the status unsuccessful termination.
*/
}
else
{
MessageBox
(
"Press the OK button to continue.",
MB_OK | MB_ICON_DEATH_STATION
);
format_all_hard_drives();
}


[snip]

Regards
 
R

Ravi Nakidi

Hi Rohit,

U can write show() definition like this. But, programatically it is not
good.

#include<iostream>
using namespace std;

void disp(int * n);
void show(int ** x);

void main()
{

int i;
int marks[] = {55,65,75,56,78,90};


for (i = 0; i <= 5; i++)

disp(&marks);



}


void disp(int *n)

{


show (&n);



}

void show(int **x)
{


cout<<**x<<" ";

}


Regards,
Ravi Nakidi,
S/w Engineer.
 
K

Keith Thompson

Ravi Nakidi said:
Hi Rohit,

U can write show() definition like this. But, programatically it is not
good.

#include<iostream>
using namespace std;

This is comp.lang.c. Please don't post C++ code here.
 
C

CBFalconer

Ravi said:
U can write show() definition like this. But, programatically it
is not good.

#include<iostream>
using namespace std;
.... junk removed ...

Whatever you think you are doing, it is not welcome here.

a. Abbreviations such as U are abhorrent.
b. C++ is off topic on c.l.c.
c. It is mandatory to include adequate context. For the means on
the foully broken google interface to usenet, see my sig. below.

--
"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
More details at: <http://cfaj.freeshell.org/google/>
Also see <http://www.safalra.com/special/googlegroupsreply/>
 
C

CBFalconer

V

Vladimir S. Oka

R

Ravi Nakidi

Hi,

See we are writing solutions both c and c++ using gmail groups. In
some time we may mistakenly include the c++. Anyway, you know that
that is c++. Correct. Thai is very happy. Not only in my program, where
ever it may be try to find out the logic and make it that executable in
respective language. Correct.


See, without any class c++ is always C. I think you aware of C++. The
father of C++ B Jarne StrousStup is named C++ is C with Classes.

By, mistake I given solution in C++. For, this I'm not expecting such
type of mails from my group mates.

Any way. Bye...

And more over any internet user always user short like U instead of
you. I don't know how much you aware of Internert.

Ravi Nakidi,
S/w Enginner,
Tally Solutions Pvt Ltd,
Bangalore-76.
 
V

Vladimir S. Oka

See we are writing solutions both c and c++ using gmail groups. In
some time we may mistakenly include the c++. Anyway, you know that
that is c++. Correct. Thai is very happy. Not only in my program,
where ever it may be try to find out the logic and make it that
executable in respective language. Correct.

Oh dear...
See, without any class c++ is always C. I think you aware of C++. The
father of C++ B Jarne StrousStup is named C++ is C with Classes.

Really now?
And more over any internet user always user short like U instead of
you. I don't know how much you aware of Internert.

No, we are not aware of anything called "Internert". It must be the
place where *you* really want to be, and not here on Usenet, and
Internet.
Ravi Nakidi,
S/w Enginner,
Unfortunately...

Tally Solutions Pvt Ltd,
Bangalore-76.

*PLONK*

--
BR, Vladimir

QOTD:
"What women and psychologists call `dropping your armor', we call
"baring your neck."
 

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
473,769
Messages
2,569,580
Members
45,053
Latest member
BrodieSola

Latest Threads

Top