I am trying to align these lines with their respective indexes. The lines look like this:
char *mystrings[] = {"Fred", "Augustine", "Bob", "Lenny", "Ricardo"};
and my conclusion is as follows:
Fred 0
Augustine 1
Bob 2
Lenny 3
Ricardo 4
But I'm for something like this:
Fred 0
Augustine 1
Bob 2
Lenny 3
Ricardo 4
As a result, the indices are aligned the same way. I'm just trying to make it more readable. This my code looks like this:
#include <stdio.h>
#include <stdlib.h>
int
main(void) {
int i;
char *mystrings[] = {"Fred", "Augustine", "Bob", "Lenny", "Ricardo"};
for (i = 0; i < 5; i++) {
printf("%s %d\n", mystrings[i], i);
}
return 0;
}
Is there a way I can do this? How to compare indices with the longest string and then create spaces for such integers?
source
share