This code asks for a name, a direction, and a number each time and saves it in an array. It asks you if you want to continue. 0 is for entering another contact and 1 is for printing the list. I tried to align each item under its title using \t it works perfectly when the strings I enter do not have spaces, but when I use spaces the strings dont align. What is the problem? I cant figure it out. Thanks in advance.
#include "stdafx.h"
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include <string.h>
void desplegar(int, char[][20], char[][20],char[][20]);
int main()
{
char nombres[20][20];
char direcciones[20][20];
char numeros[20][20];
int opcion = 0;
int contactos = 0;
system("hostname");
do {
printf("\nIngrese el nombre del contacto: ");
gets(nombres[contactos]);
printf("\nIngrese la direccion del contacto: ");
gets(direcciones[contactos]);
printf("\nIngrese el numero del contacto: ");
gets(numeros[contactos]);
contactos++;
printf("\nDesea ingresar otro contacto? (0/1): ");
scanf("%d",&opcion);
getchar();
}while(opcion != 1 && contactos < 20);
desplegar(contactos,nombres,direcciones,numeros);
printf("\n");
system("pause");
return 0;
}
void desplegar(int cantidad,char nombres[][20],char direcciones[][20],char numeros[][20]){
printf("Nombres\t\tDirecciones\t\tTelefono\n");
for (int i = 0; i < cantidad; i++){
printf("%s\t\t%s\t\t%s\n",nombres[i],direcciones[i],numeros[i]);
}
}