C program how to print in table format alignment

C program how to print in table format alignment

The code to print the inventory should use the length specifier in printf format like this:

n

gotoxy(0, 10);nwhile (fscanf(fp, %d %s %d %f, &a.id, a.name, &a.quantity, &a.price) == 4) {n    printf(    %-10d\t\t %-12s\t\t %8d\t %8.2f\n\n, a.id, a.name, a.quantity, a.price);n}n

n

Some notes regarding the code:

n

    • n

    • it is very bad style to call main() recursively. Use a loop instead.

n

    • write a function that prints the header instead of duplicating the code multiple times.

n

    • the statement int main(); at the end of displayProduct() is a local declaration for function main, it does not generate a call.

n

your menu doesnt go back to the main menu after pressing any key,nthere you have to use main(); instead ogf int main();

C program how to print in table format alignment

Leave a Reply

Your email address will not be published.