0

So I have this function :

char *lookUpPageTable(char **array, int VPN)
   {
   if (array[VPN][0] == '1')
      {
      /*char **pageNumber = (char **)malloc(sizeof(char*)* 128);
        for (int i = 0; i < strlen(array); i++)
           {
           pageNumber[i] = array[VPN][i];
           }*/

      return array[VPN]; //this returns the whole number which I dont want
      }
   else
      {
      return "Page Fault";
      }
   }

The array I'm passing in as a parameter holds a list of numbers in the form 1 123456 where the first number is either a 1 or a 0 and the second number is a random number. This function checks the first number at index VPN in the array. If it is a zero, it should return a "Page Fault" string. If it is a 1, then the function should return the number after the 1.

For example, if i called lookUpPageTable(array, index)

The method should see if array[index][0] == '1'

If it does then return the remaining numbers at array[index]

else

return "page fault"

1 Answer 1

1

array[VPN] is the VPN-th element of the array, which happens to be a pointer to the string "1 123456" as you say. If you return array[VPN] + 1, for example, it would be a pointer to the string " 123456".

So you may return array[VPN] + 2, and you will obtain a pointer to the string "123456" as desired.

Note, however, that I am relying on your guarantee that the string's contents are indeed something of the form "1 123456", and I would recommend that your code should also verify that the string really is of that form.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.