I have written a printk function, and I can output text now. I have tried to add the ability to pass variables, int primarily, but everything I have tried the video memory just outputs weird characters. My printk function prototype is
printk(const char*, unsigned int line, char *data);
How should I be passing the variables to my printk function? Because my video_mem is declared as char* I assume anything I assign to video_mem[v] will be printed out as a char, right? Do I have to create a new video memory variable of type int to print out integer variables?
printing out integers, floats
Re:printing out integers, floats
Read up on variable argument lists: the ... keyword and the <stdarg.h> header file.
Re:printing out integers, floats
I can't find anything in stdarg.h that is of any help. I have another question, what does the ... in functions mean?
ie - int printf (const char*, ...);
If anyone could answer any of these, it would be appreciated.
ie - int printf (const char*, ...);
If anyone could answer any of these, it would be appreciated.
Re:printing out integers, floats
It's all normal, everyday C code. You need to look these up wherever you learned C originally -- a web board is not the right place to study such fundamental things as the core C language.
Briefly, int printf(const char *fmt, ...) means that printf can take any number of parameters after fmt. printf's code can access these extra parameters using the macros in <stdarg.h>.
Briefly, int printf(const char *fmt, ...) means that printf can take any number of parameters after fmt. printf's code can access these extra parameters using the macros in <stdarg.h>.
Re:printing out integers, floats
printf(const char *, ...) means you can have any number of args after the const char *. To access the args in your function you need a pointer to the last named arg and just increase it to make it point to the rest of the args. (Usually done with the va_start, va_arg and va_end macros).
To output integers to the screen you have to convert them to a string first.
To output integers to the screen you have to convert them to a string first.