Results 1 to 5 of 5
Hello everbody:
Im having problems with this little thing in a C example Im doing.
I want to show in the shell like this example:
Name Birthday
Tomas 13
Adrian ...
- 05-10-2010 #1Just Joined!
- Join Date
- Mar 2010
- Posts
- 12
C. How to arrange the results in the shell [Solved]
Hello everbody:
Im having problems with this little thing in a C example Im doing.
I want to show in the shell like this example:
Name Birthday
Tomas 13
Adrian 24
Nate 15
Im trying to use the printf function but the names doesnt have the same lenght, so any idea?
So I cant do it like this:
printf("Name Bithday\n");
printf("%s %d\n");
- 05-11-2010 #2Just Joined!
- Join Date
- Apr 2010
- Location
- India
- Posts
- 3
- 05-11-2010 #3Just Joined!
- Join Date
- Mar 2010
- Posts
- 12
Hello vmandale
the thing is that if I put it like that it doesnt make right, because the names havent got the same length. Maybe using some options from the shell?
- 05-11-2010 #4
When using printf, you actually can specify the length of your data:
This will force the name to be six characters, and the birthday to be 2 characters. Spaces will be added to the left of the output if it is not long enough.Code:printf("%6s %2d\n", name, birthday);
Note that if any of your data is longer than 6 characters, this will not work (it will not shrink output). Therefore, you will want to use the longest width that you have to.DISTRO=Arch
Registered Linux User #388732
- 05-11-2010 #5Just Joined!
- Join Date
- Mar 2010
- Posts
- 12


Reply With Quote
