Colocación de salida en C usando pestañas problema

How can I make sure not to happen like this? Is there any way to show exact place by numbers?

Name            UID     GID     Dir     Host
root    0       0       /root
paingpyi        500     500     /home/paingpyi  192.168.12.1
paingpyi        500     500     /home/paingpyi  192.168.12.1

El código es

printf("Name \t\tUID \tGID \tDir \tHost\n");
printf("%s \t\t%d \t%d \t%s \t%s \n",up->ut_user,pw->pw_uid,pw->pw_gid,pw->pw_dir,up->ut_host);

preguntado el 08 de enero de 11 a las 20:01

1 Respuestas

La printf width specifiers are more appropriate for this kind of tasks than \t. You should have a look into the 'field width' section of el manual.

Respondido el 08 de enero de 11 a las 23:01

specifically, he should use something like %-16.16s for strings and %-8d for integers - Christoph

What if I also want to format for Header? I don't have any $s or $d for Header line. What shall I do? - Devyn

@Devyn you can use something such as printf("%-16s%-8s%-8s\n", "Name", "UID", "GID") - hielo

Wow.. I've never thought like that. That's a great answer :) Thanks a lot for everyone! - Devyn

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.