1

I am trying to print some stats about the hole struct in MINIX 3 kernel, I have modified the file alloc.c to print the number of holes in the list, number of iterations before a hole in the list was found and average size of the holes. I use printf to print to the console but it keeps printing type specifiers to the console screen. Here is a piece of my code:

printf("Total number of holes: %i\n", numHoles);

the output is:

Total number of holes: %i

It is printing the specifier as if it didn't recognize the type specifier. I declared numHoles as int numHoles = 0; and just incremented it in a loop structure. I have also added #include <stdio.h> to the top of the file. What am I doing wrong?

  • 2
    Have you tried `%d` or `%u`? – William Pursell Oct 16 '15 at 22:19
  • 2
    Are you doing this in the MINIX kernel? `printf()` may not be available in the kernel, there's usually a simpler function. – Barmar Oct 16 '15 at 22:21
  • Can you show a [mcve]? – t0mm13b Oct 16 '15 at 22:23
  • @t0mm13b What exactly are you missing? The code, the output and the explanations are all there. – GolezTrol Oct 16 '15 at 22:23
  • No, I have one other printf statement that prints the average that is a float value using the %f specifier and the same thing happens, %f literally gets printed to the screen. So I assume it's not the type being used that is the issue. But I'll try it anyway. @WilliamPursell – Ronnie Van Dyk Oct 16 '15 at 22:26
  • @GolezTrol the question is assuming that its a standard console stuff.. am surprised that the runtime is not specifying it, what command was used to compile/link, that's what I was referring to, a one liner does not just cut it. – t0mm13b Oct 16 '15 at 22:28
  • `%f` isn't always implemented either. Try a basic test with `%d` and if necessary cast the value with `(int)` – Weather Vane Oct 16 '15 at 22:30
  • @Barmar Yes it is in the kernel. What other functions exist? – Ronnie Van Dyk Oct 16 '15 at 22:33
  • Think you should amend your question to state that its a kernel code, printf would not be available, perhaps a more simpler printf without format specifiers? see [this](http://stackoverflow.com/questions/10847666/minix-print-from-kernel-to-console) – t0mm13b Oct 16 '15 at 22:35
  • 2
    I don't know about MINIX specifically, but Unix kernels have [`printk()`](http://unix.stackexchange.com/questions/118976/how-exactly-does-printk-work-internally). – Barmar Oct 16 '15 at 22:36

0 Answers0