2

I once managed to return the function, and with that when I run the test it passed I Have this function on utils.c:

  int (util_sys_inb)(int port, uint8_t *value) {

         uint32_t val;

          if(sys_inb(port, &val) != OK) return 1;

          *value = (uint8_t)val;

          return 0;

         }

This one is just for wrapping up the function sys_inb(), because of the format of the argument. Then I need to get right the number of times that this is called. I have this other file : keyboard.c with a global variable, extern int count.

with this function:

       int sys_inb_count(int port, uint8_t *value) {

if(util_sys_inb(port,value)!=OK){ return 1;}

      count++;

      return count;

   }

I got this right once, returning the value on the first function, but then I did something differently, and the tests were not able to pass anymore. Appreciate if you can help, me, I've been pulling my hair out.

I tried, put the counter straight on the first function and it worked, but then I tried to do it again, and then I could not anymore.

It compiles and runs but I get this: https://i.stack.imgur.com/tFpVR.jpg

  • Where is `count` being initialized? – daShier Oct 16 '19 at 13:26
  • @daShier out of the function , I just did not mention, and on the keyboard.h I have it like extern int cout; – Fernando Gardeazabal Oct 16 '19 at 13:27
  • 2
    So is `OK` equal to 1 or 0? You don't increment `count` if something other than `OK` is returned. Why do you need to return `count` if it's a global? But we'd need to see more code to really investigate. – 500 - Internal Server Error Oct 16 '19 at 13:46
  • I don't have to actually return count, I can return one of the other functions since they return an integer.But they return 0 if it works,if it does not work 1. So the OK is 0. I could change them to return the counter inside of it, instead of doing it on the keyboard.c file which is not making it work. – Fernando Gardeazabal Oct 16 '19 at 17:39
  • The screenshot you provide shows 12 lines of output, and a count of 12. Why is this not correct? Please give us a [example] accompanied with input, expected output and received output! BTW, you should copy text directly in your question instead of a screenshot. – the busybee Oct 16 '19 at 18:27
  • I can't copy text from the minix virtual machine, sorry. – Fernando Gardeazabal Oct 16 '19 at 19:33

1 Answers1

0

The problem was that I was only adding to the counter when the function worked as expected, if it was called and gave an error, it would not count I just added the counter to the util_sys_inb:

uint32_t count = 0;

int (util_sys_inb)(int port, uint8_t *value) {

   uint32_t val;

    if(sys_inb(port, &val) != OK) return 1;

      *value = (uint8_t)val;

      count++;

      return count;

        }