Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

I need help with this program to display an array using a function.

Posted on 2006-11-08
9
Medium Priority
?
177 Views
Last Modified: 2010-04-24
Hi experts,

I need to find out what would be the correct way (command) of calling the showArray function

right after "sortArray();" on main()

so that I can diplay the fifty random integers that were sorted.

Thanks for your help.
0
Comment
Question by:manz2
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 3
9 Comments
 
LVL 45

Expert Comment

by:sunnycoder
ID: 17904210
Hi manz2,

Yes you can call showArray after sortArray.
It need not be immediately after sortArray, as long as
a) It is placed after sort array
b) Intervening code does not change the order of elements in the array

Cheers!
sunnycoder
0
 
LVL 45

Expert Comment

by:sunnycoder
ID: 17904213
> a) It is placed after sort array
I meant ... It is called anytime after sortArray (and not physical code placement)

Cheers!
sunnycoder
0
 

Author Comment

by:manz2
ID: 17904229
sorry, maybe I did not explain myself correctly

I want to know how would I call it.

I got the function from the book that was used in another
program.

In the book they used:

const in SIZE = 6;
int values[size] = {1,2,3,4,5,6};
showArray (values, SIZE);

How can I adapt that call statement to mine since I had them generated randomly and then sorted.
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 45

Expert Comment

by:sunnycoder
ID: 17904239
Random generation does not make any difference to the function ... All that function does is accept an array and display it ... it does not know if the array was sorted, or unordered or randomly generated or read from file!!! ... that is the whole purpose of having functions ... isolate useful functionality

However, in order to display correctly, it needs to know how many elements were there in the array... For this purpose, you might like to pass it an argument which would indicate the size (number of elements) of the array.

You would still call the function as
showArray (my_random_array, num_elements_in_my_array);

Cheers!
sunnycoder
0
 

Author Comment

by:manz2
ID: 17904298
showArray(my_random_array,50);

obviously I would put 50 for number of elements, since I have generated 50 radnom integers.
but what number or variable from the program would I put in my_random_array to describe all?

thanks.
0
 
LVL 45

Expert Comment

by:sunnycoder
ID: 17904306
Simply put name of your array!!

the function will receive the address of the first element of the array (a pointer)
0
 
LVL 45

Accepted Solution

by:
sunnycoder earned 2000 total points
ID: 17904314
0
 

Author Comment

by:manz2
ID: 17904396
You know what?

I had tried that before I asked you:

showArray(numarray,50);

but I got an error when compiling, telling me it could not convert from unsigned to int.

So i changed numarray from unsigned to just int at the start of the program and it worked.

That's why I figured I still wasn't doing something right.

But it works now.

Thanks for your patience sunnycoder, I don't mean to sound like an idiot, I'm sure you understand that
as a beginner this stuff can seem mind boggling at times. ;)
0
 
LVL 45

Expert Comment

by:sunnycoder
ID: 17905451
Good to know that it is working now ... If you post the attempts you have already made and the errors/problems you faced, I am sure you would receive more precise help. It is an excellent approach to try things and is far more enriching when you find out why somethings work while others dont ... :)
0

Featured Post

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

The following diagram presents a diamond class hierarchy: As depicted, diamond inheritance denotes when two classes (e.g., CDerived1 and CDerived2), separately extending a common base class (e.g., CBase), are sub classed simultaneously by a fourt…
In Easy String Encryption Using CryptoAPI in C++ (http://www.experts-exchange.com/viewArticle.jsp?aid=1193) I described how to encrypt text and recommended that the encrypted text be stored as a series of hexadecimal digits -- because cyphertext may…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

610 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