473,325 Members | 2,870 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

functions arrays and pointers problem

18
I want to print the results of the best schedule array (which is shorted in a specific way in the find_best_scedule function) through the main program. Actually I should print the results by using a second function named print_best_schedule, but this seems too complicated and I prefer to do one step at a time.

The problem is that I don't know how to print the array through the pointer "ptr".

Here is the code I wrote:

Expand|Select|Wrap|Line Numbers
  1. void find_best_schedule(int TASK_TIMES[6][3],int *ptr[7]);
  2. int print_best_schedule(int best_schedule[]);
  3.  
  4. ...
  5.  
  6. int TASK_TIMES[][3] = { {1,15,3}, {2,7,9}, {3,4,10}, {4,7,6}, {5,10,9}, {6,4,5}, {7,7,8}};
  7. int ptrs, k;
  8. find_best_schedule(TASK_TIMES, &ptrs);
  9.  
  10. for(k=0; k<7; k++)
  11.     printf("%d",ptrs[k]);//Here is the problem
  12.  
  13.  
  14. ...
  15.  
  16.  void find_best_schedule(int TASK_TIMES[6][3],int*ptr[7])
  17.  {
  18.   int i, k, p, n, min, cell, in_schedule[7], best_schedule[7];
  19.  
  20.     <snipped:- code populating best scheduled array>
  21.  
  22.     ptr[7]=&best_schedule[0];
  23.  
  24. }
Mar 4 '08 #1
8 1496
gpraghuram
1,275 Expert 1GB
Is this code compiling for you.?
I was not able to compile this.
You are passing an integer address and getting it in a pointer array...how it will compile

Raghuram
Mar 5 '08 #2
xrysa
1
Please help me!!!!!!!!!! I have the same problem in a homework and i can't find the problem. Can you check exactly in the code what to correct?

Thank you
Xrysa
Mar 5 '08 #3
Banfa
9,065 Expert Mod 8TB
cube, you have made a number of posts now, please start using code tags ([code=c] ... [/code]) round code you post. I have added them for you this time.
Mar 5 '08 #4
weaknessforcats
9,208 Expert Mod 8TB
Please help me!!!!!!!!!!
Didn't you read that your code won't compile??

Your function needs a pointer to an array of 7 int and you are passing a pointer to a single int.
Mar 5 '08 #5
cube
18
cube, you have made a number of posts now, please start using code tags (
Expand|Select|Wrap|Line Numbers
  1.  ... 
) round code you post. I have added them for you this time.

Sorry, I post this code late after midnight and I did look for it but I didn't remember which symbol to click. Now I know!!!
Mar 5 '08 #6
cube
18
Please help me!!!!!!!!!!


Didn't you read that your code won't compile??

Your function needs a pointer to an array of 7 int and you are passing a pointer to a single int.

Please note that I wasn't the one that "Pleased for help" but Xrysa.

Thank you for pointing it out for me. I did try to read about pointers and arrays before post this code but I couldn't understand much, about the particular assignment.
Can I find the answer to my question in the article "Arrays Revealed"?
Mar 5 '08 #7
cube
18
Finally there is a more simple way to do this without pointers.

But just to enrich my knowledge I would like to find how to do it both ways.
Mar 5 '08 #8
weaknessforcats
9,208 Expert Mod 8TB
Can I find the answer to my question in the article "Arrays Revealed"?
Read the article and let me know if I have to add sonmething to it.

Also,
Please note that I wasn't the one that "Pleased for help" but Xrysa.
Sorry. My mistake.
Mar 6 '08 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

21
by: Matteo Settenvini | last post by:
Ok, I'm quite a newbie, so this question may appear silly. I'm using g++ 3.3.x. I had been taught that an array isn't a lot different from a pointer (in fact you can use the pointer arithmetics to...
5
by: buda | last post by:
Hi, given the following code, .... int main( void ) { char *a = { "abc", "def", "ghijkl", "o", "prs" }; // for example .... }
5
by: Steve | last post by:
Can anyone tell me if I can have an array of functions that take a variable number of parameters? If it is possible I'd like to know how to declare the array and the functions as its elements. I am...
10
by: Pete | last post by:
Can someone please help, I'm trying to pass an array to a function, do some operation on that array, then return it for further use. The errors I am getting for the following code are, differences...
5
by: Bern McCarty | last post by:
I have a DLL written in C++ (it's really C code that was adjusted to compile OK as C++) that I compile successfully into IL with the /CLR switch of Visual C 7.1. I use the resultant library...
1
by: ashutosh | last post by:
hi, i am making the dll for clamav antivirus libraray so that i can make activex control for windows. i complied the library successfully and make the Libclamav.dll file using win32 Api...
47
by: Albert | last post by:
So structures are useful to group variables, so you can to refer to a collection as a single entity. Wouldn't it be useful to also have the ability to collect variable and functions? Ask K&R...
3
by: googlinggoogler | last post by:
Hi This should all be pretty standard C stuff, but I'm going to use terms like mouse callback to communicate what Im tyring to do. Basically I have my program whirling around in an infinite...
20
by: J de Boyne Pollard | last post by:
MThe library functions which are included to allow process Mlaunch, forking, and termination, imply that it is both Mpossible and desirable for a process to fork itself. This is Ma fundamental...
127
by: sanjay.vasudevan | last post by:
Why are the following declarations invalid in C? int f(); int f(); It would be great if anyone could also explain the design decision for such a language restricton. Regards, Sanjay
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.