I am trying to create a simplified version of printf() but without the use of va_list, va_start, va_arg and va_end.
My original idea is to have:
void my_printf (char *format, ...);
Then, go through the format, and count the number of % (arguments) to find out how many variables were passed to my function. From there, I was thinking of creating a buffer based on how many arguments there are, then combine then and use write() to finally output them.
Is there a better way of approaching this problem? Will I run into issues with my plan?
Any help would be greatly appreciated.
Some of my brainstorming code is:
// Count arguments
int cnt_s, cnt_c, cnt_d, cnt_u, cnt_x;
for (; *format; format++) {
switch(format[0]) {
case '%':
switch(format[1]) {
case 'd':
cnt_d++;
}
}
}
va_list,va_start,va_arg, andva_endto access the arguments specified by the...- pmg...then? - Pat