Ok, I'm using Ubuntu with gcc to compile C programs and I'm doing a simple supermarket inventory tool. Everything's fine, but look at the printing in the option 2.
I run option one of the switch to add articles and their quantity, the second option has to print each articles and how many we have. But, look at the rare, tab? printing.
This is the line that got a problem.
Code:
printf("1.%79s = %d.2. %79s = %d.3. %79s = %d.", nart1, art1, nart2, art2, nart3, art3);
What should I do? The "79s" printing is the problem? Thanks in advance.
Code:
#include <stdio.h>
#include <stdlib.h>
int main()
{
signed int art1, art2, art3, opt;
char nart1[20], nart2[20], nart3[20], answer, user[10];
printf("\a\7\n");
printf("Digite su nombre, por favor\n");
scanf("%79s", user);
system("clear");
do {
printf("Bienvenido %s, digite una opción.\n 1. Agregar artículos. \n 2. Ver artículos con sus existencias. \n 3. Hacer movimientos de inventario. \n 4. Salir.\n", user);
scanf("%d", & opt);
switch(opt) {
case 1:
printf("¿Cómo se llama el artículo 1?\n");
scanf("%79s", nart1);
printf("¿Cuántos hay del artículo 1?\n");
scanf("%d", & art1);
printf("¿Cómo se llama el artículo 2?\n");
scanf("%79s", nart2);
printf("¿Cuántos hay del artículo 2?\n");
scanf("%d", & art2);
printf("¿Cómo se llama el artículo 3?\n");
scanf("%79s", nart3);
printf("¿Cuántos hay del artículo 3?\n");
scanf("%d", & art3);
break;
case 2:
if(nart1 && nart2[0] == '\0') {
printf("Por favor ingresa valores antes de pedir mostrarlos");
break; }
printf("1.%79s = %d.2. %79s = %d.3. %79s = %d.", nart1, art1, nart2, art2, nart3, art3);
break;
case 3:
/* ........, this is the worst part */
case 4:
exit(0);
}
printf("¿Desea continuar?\n");
scanf("%79s", & answer);
}while(answer == 's' || answer == 'S');
return 0;
}