How do I write a list of numbers using C?
I am making a list of fields using 'printf' and I want to number that list of fields. For example: printf("1 Catch \n" "2 Throw \n" "3 Field \n"); Or printf("%d Catch, \n" "%d Throw, \n" 1, 2); However, I don't want to number them myself. Do I need to use an array to create this numbered list? Or is there a simpler way?
Public Comments
- I would probably change the problem and use a program like this: #include <stdio.h> char *Strings[ ] = { "Catch", "Throw", "Field", NULL }; int main() { int I; for (I = 0; Strings[ I ]; I++) { printf("%d %s\n", I + 1, Strings[ I ]); } return 0; }
Powered by Yahoo! Answers