Im new to C and trying to format a string that correlates to the spacing of another.
I am aiming for the example output below:
Orders for Pizzeria Freddy's # Customer Pizza Price Time ------------------------------------------------------------------------ 01 >Fred Hawaiian $15.99 15 To do this i made two functions:
void print_header(struct pizzeria *the_pizzeria) { printf("Orders for Pizzeria %s\n", the_pizzeria->name); printf("# Customer Pizza Price Time\n"); printf("------------------------------------------------------------------------\n"); } and
void print_order(struct order *the_order, int order_number, bool selected) { if (selected == true){ printf("%02d >%4s %20s $%0.2f %20s\n", order_number, the_order->customer, the_order->pizza, the_order->cost, the_order->time); } else{ printf("%02d %4s %20s $%0.2f %20s\n", order_number, the_order->customer, the_order->pizza, the_order->cost, the_order->time); } } I have also tried using %20s to format the string in function print_order but got errors and not the intended output:
void print_order(struct order *the_order, int order_number, bool selected) { if (selected == true){ printf(("%02d >%4s" + String.format("%20s", the_order->pizza) + "$%0.2f" + String.format("%20s\n", the_order->time)), order_number, the_order->customer the_order->cost); } else{ printf(("%02d >%4s" + String.format("%20s", the_order->pizza) + "$%0.2f" + String.format("%20s\n", the_order->time)), order_number, the_order->customer the_order->cost); } }