functions arrays and pointers problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • cube
    New Member
    • Feb 2008
    • 18

    functions arrays and pointers problem

    I want to print the results of the best schedule array (which is shorted in a specific way in the find_best_scedu le function) through the main program. Actually I should print the results by using a second function named print_best_sche dule, 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:

    [code=c]
    void find_best_sched ule(int TASK_TIMES[6][3],int *ptr[7]);
    int print_best_sche dule(int best_schedule[]);

    ...

    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}};
    int ptrs, k;
    find_best_sched ule(TASK_TIMES, &ptrs);

    for(k=0; k<7; k++)
    printf("%d",ptr s[k]);//Here is the problem


    ...

    void find_best_sched ule(int TASK_TIMES[6][3],int*ptr[7])
    {
    int i, k, p, n, min, cell, in_schedule[7], best_schedule[7];

    <snipped:- code populating best scheduled array>

    ptr[7]=&best_schedu le[0];

    }[/code]
    Last edited by Banfa; Mar 5 '08, 09:22 PM. Reason: Code removed at users request, conformance to posting guidelines
  • gpraghuram
    Recognized Expert Top Contributor
    • Mar 2007
    • 1275

    #2
    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

    Comment

    • xrysa
      New Member
      • Mar 2008
      • 1

      #3
      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

      Comment

      • Banfa
        Recognized Expert Expert
        • Feb 2006
        • 9067

        #4
        cube, you have made a number of posts now, please start using code tags (&#91;code=c&#9 3; ... &#91;/code&#93;) round code you post. I have added them for you this time.

        Comment

        • weaknessforcats
          Recognized Expert Expert
          • Mar 2007
          • 9214

          #5
          Originally posted by cube
          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.

          Comment

          • cube
            New Member
            • Feb 2008
            • 18

            #6
            Originally posted by Banfa
            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.

            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!!!

            Comment

            • cube
              New Member
              • Feb 2008
              • 18

              #7
              Originally posted by Xrysa
              Please help me!!!!!!!!!!


              Originally posted by weaknessforcats
              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"?

              Comment

              • cube
                New Member
                • Feb 2008
                • 18

                #8
                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.

                Comment

                • weaknessforcats
                  Recognized Expert Expert
                  • Mar 2007
                  • 9214

                  #9
                  Originally posted by cube
                  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,
                  Originally posted by cube
                  Please note that I wasn't the one that "Pleased for help" but Xrysa.
                  Sorry. My mistake.

                  Comment

                  Working...