Hola!

Registrándote como bakuno podrás publicar, compartir y comunicarte en privado con otros bakuos :D

Regístrame ya!

problemas con funciones y structs

batiguason_11

Bovino adicto
Desde
27 Jun 2009
Mensajes
703
Veran tengo mi siguiente código pero no se que tan correcto este o si lo que hago esta permitido y número 2 también no sé si usar apuntadores seria mejor en este caso :S podrian ayudarme a revisar mi código y decirme mis errores al compilar me sale

ld: in tienda_mod, can't link with a main executable
collect2: ld returned 1 exit status

solo dos errores, programo bajo ANSI C en Linux su ayuda me podria ayudar :D

#include <stdio.h>
#include<string.h>
struct articulos {
char art[5][50];
float pre[5],tot[T];
int can[5];
char menu () {
char op;
struct articulos comp;
strcpy(comp.art[0],"papel");
strcpy(comp.art[1],"colores");
strcpy(comp.art[2],"libreta");
strcpy(comp.art[3],"carpeta");
strcpy(comp.art[4],"plumas");
comp.pre[0]=.50;
comp.pre[1]=5.43;
comp.pre[2]=20;
comp.pre[3]=10;
comp.pre[4]=4.5;
printf("\n\tARTICULOS\t\tPrecio");
printf("\n\t 1- %s\t\t%.2F",comp.art[0],comp.pre[0]);
printf("\n\t 2- %s\t\t%.2F",comp.art[1],comp.pre[1]);
printf("\n\t 3- %s\t\t%.2F",comp.art[2],comp.pre[2]);
printf("\n\t 4- %s\t\t%.2F",comp.art[3],comp.pre[3]);
printf("\n\t 5- %s\t\t%.2F",comp.art[4],comp.pre[4]);
printf("\n\t\t\tque desea comprar? ");
fpurge(stdin);
scanf("%c",&op);
scanf("%c",&op);
return op;
}
void total(int con1,int con2,int con3,int con4,int con5) {
struct articulos comp;
comp.pre[0]=.50;
comp.pre[1]=5.43;
comp.pre[2]=20;
comp.pre[3]=10;
comp.pre[4]=4.5;
strcpy(comp.art[0],"papel");
strcpy(comp.art[1],"colores");
strcpy(comp.art[2],"libreta");
strcpy(comp.art[3],"carpeta");
strcpy(comp.art[4],"plumas");
printf("\n\nProducto\t\tCantidad\tSubtotal");
printf("\n\n%s\t\t\t%i\t\t%.2F",comp.art[0],con[0],comp.tot[0]);
printf("\n%s\t\t\t%i\t\t%.2F",comp.art[1],con[1],comp.tot[1]);
printf("\n%s\t\t\t%i\t\t%.2F",comp.art[2],con[2],comp.tot[2]);
printf("\n%s\t\t\t%i\t\t%.2F",comp.art[3],con[3],comp.tot[3]);
printf("\n%s\t\t\t%i\t\t%.2F",comp.art[4],con[4],comp.tot[4]);
printf("\n\t\t\t\tTotal= %.2F\n",total);
}
main () {
char p,op;
int con[5],comp_total[5],total;
do {
p=menu();
switch (op) {
case '1': con[0]++;
break;
case '2': con[1]++;
break;
case '3': con[2]++;
break;
case '4': con[3]++;
break;
case '5': con[4]++;
break;
default: printf("\nOpcion no valida");
}
printf("\ndesea seguir comprando?y/n ");
fpurge(stdin);
scanf("%c",&op);
}
for (i=0;i<5;i++) {
comp_total=con*comp.pre;
total+=comp_total;
}
total(con1,con2,con3,con4,con5);
return 0;
}
 
De entrada, lo que veo es que no has declarado las funciones... las estas "haciendo" pero no declarando....

otra que veo, es que en tu switch del main, estas evaluando la variable "op" cuando segun yo, deberias de evaluar a "p" que es el valor retornado de tu funcion "menu".

la ultima, es que tu struct esta medio raro... por que incluyes ahi un menu?


PD: Cual es el problema a resolver?
 
Bueno aqui esta lo que me marco el Codeblocks:

------------ Build: Debug in struct ---------------

Compiling: main.c
C:\Users\\Desktop\struct\main.c:5: error: `T' undeclared here (not in a function)
C:\Users\\Desktop\struct\main.c:7: error: field `menu' declared as a function
C:\Users\\Desktop\struct\main.c:7: warning: no semicolon at end of struct or union
C:\Users\\Desktop\struct\main.c:7: error: syntax error before '{' token
C:\Users\\Desktop\struct\main.c:10: error: syntax error before '.' token
C:\Users\\Desktop\struct\main.c:10: warning: type defaults to `int' in declaration of `strcpy'
C:\Users\\Desktop\struct\main.c:10: error: conflicting types for 'strcpy'
C:\Users\\Desktop\struct\main.c:10: error: conflicting types for 'strcpy'
C:\Users\\Desktop\struct\main.c:10: warning: data definition has no type or storage class
C:\Users\Pabliman\Desktop\struct\main.c:11: error: syntax error before '.' token
C:\Users\Pabliman\Desktop\struct\main.c:11: warning: type defaults to `int' in declaration of `strcpy'
C:\Users\\Desktop\struct\main.c:11: warning: data definition has no type or storage class
C:\Users\\Desktop\struct\main.c:12: error: syntax error before '.' token
C:\Users\\Desktop\struct\main.c:12: warning: type defaults to `int' in declaration of `strcpy'
C:\Users\\Desktop\struct\main.c:12: warning: data definition has no type or storage class
C:\Users\\Desktop\struct\main.c:13: error: syntax error before '.' token
C:\Users\\Desktop\struct\main.c:13: warning: type defaults to `int' in declaration of `strcpy'
C:\Users\\Desktop\struct\main.c:13: warning: data definition has no type or storage class
C:\Users\\Desktop\struct\main.c:14: error: syntax error before '.' token
C:\Users\\Desktop\struct\main.c:14: warning: type defaults to `int' in declaration of `strcpy'
C:\Users\\Desktop\struct\main.c:14: warning: data definition has no type or storage class
C:\Users\Desktop\struct\main.c:15: error: syntax error before '.' token
C:\Users\\Desktop\struct\main.c:20: error: syntax error before string constant
C:\Users\\Desktop\struct\main.c:20: warning: type defaults to `int' in declaration of `printf'
C:\Users\\Desktop\struct\main.c:20: error: conflicting types for 'printf'
C:\Users\\Desktop\struct\main.c:20: note: a parameter list with an ellipsis can't match an empty parameter name list declaration
C:\Users\\Desktop\struct\main.c:20: error: conflicting types for 'printf'
C:\Users\\Desktop\struct\main.c:20: note: a parameter list with an ellipsis can't match an empty parameter name list declaration
C:\Users\\Desktop\struct\main.c:20: warning: data definition has no type or storage class
C:\Users\\Desktop\struct\main.c:21: error: syntax error before string constant
C:\Users\\Desktop\struct\main.c:21: warning: type defaults to `int' in declaration of `printf'
C:\Users\\Desktop\struct\main.c:21: warning: data definition has no type or storage class
C:\Users\\Desktop\struct\main.c:22: error: syntax error before string constant
C:\Users\\Desktop\struct\main.c:22: warning: type defaults to `int' in declaration of `printf'
C:\Users\\Desktop\struct\main.c:22: warning: data definition has no type or storage class
C:\Users\\Desktop\struct\main.c:23: error: syntax error before string constant
C:\Users\\Desktop\struct\main.c:23: warning: type defaults to `int' in declaration of `printf'
C:\Users\\Desktop\struct\main.c:23: warning: data definition has no type or storage class
C:\Users\\Desktop\struct\main.c:24: error: syntax error before string constant
C:\Users\\Desktop\struct\main.c:24: warning: type defaults to `int' in declaration of `printf'
C:\Users\\Desktop\struct\main.c:24: warning: data definition has no type or storage class
C:\Users\\Desktop\struct\main.c:25: error: syntax error before string constant
C:\Users\\Desktop\struct\main.c:25: warning: type defaults to `int' in declaration of `printf'
C:\Users\\Desktop\struct\main.c:25: warning: data definition has no type or storage class
C:\Users\\Desktop\struct\main.c:26: error: syntax error before string constant
C:\Users\\Desktop\struct\main.c:26: warning: type defaults to `int' in declaration of `printf'
C:\Users\\Desktop\struct\main.c:26: warning: data definition has no type or storage class
C:\Users\\Desktop\struct\main.c:27: error: syntax error before '(' token
C:\Users\\Desktop\struct\main.c:28: error: syntax error before string constant
C:\Users\\Desktop\struct\main.c:28: warning: type defaults to `int' in declaration of `scanf'
C:\Users\\Desktop\struct\main.c:28: error: conflicting types for 'scanf'
C:\Users\\Desktop\struct\main.c:28: note: a parameter list with an ellipsis can't match an empty parameter name list declaration
C:\Users\\Desktop\struct\main.c:28: error: conflicting types for 'scanf'
C:\Users\\Desktop\struct\main.c:28: note: a parameter list with an ellipsis can't match an empty parameter name list declaration
C:\Users\\Desktop\struct\main.c:28: warning: data definition has no type or storage class
C:\Users\\Desktop\struct\main.c:29: error: syntax error before string constant
C:\Users\Pabliman\Desktop\struct\main.c:29: warning: type defaults to `int' in declaration of `scanf'
C:\Users\Pabliman\Desktop\struct\main.c:29: warning: data definition has no type or storage class
C:\Users\Pabliman\Desktop\struct\main.c: In function `total':
C:\Users\Pabliman\Desktop\struct\main.c:33: error: storage size of 'comp' isn't known
C:\Users\\Desktop\struct\main.c:45: error: `con' undeclared (first use in this function)
C:\Users\\Desktop\struct\main.c:45: error: (Each undeclared identifier is reported only once
C:\Users\\Desktop\struct\main.c:45: error: for each function it appears in.)
C:\Users\\Desktop\struct\main.c:33: warning: unused variable `comp'
C:\Users\\Desktop\struct\main.c: At top level:
C:\Users\\Desktop\struct\main.c:52: warning: return type defaults to `int'
C:\Users\\Desktop\struct\main.c: In function `main':
C:\Users\\Desktop\struct\main.c:56: warning: implicit declaration of function `menu'
C:\Users\\Desktop\struct\main.c:71: warning: implicit declaration of function `fpurge'
C:\Users\\Desktop\struct\main.c:74: error: syntax error before "for"
C:\Users\Desktop\struct\main.c:74: error: `i' undeclared (first use in this function)
C:\Users\\Desktop\struct\main.c:74: error: syntax error before ')' token
C:\Users\\Desktop\struct\main.c: At top level:
C:\Users\\Desktop\struct\main.c:78: warning: type defaults to `int' in declaration of `total'
C:\Users\\Desktop\struct\main.c:78: warning: parameter names (without types) in function declaration
C:\Users\\Desktop\struct\main.c:78: error: conflicting types for 'total'
C:\Users\\Desktop\struct\main.c:32: error: previous definition of 'total' was here
C:\Users\\Desktop\struct\main.c:78: warning: data definition has no type or storage class
C:\Users\\Desktop\struct\main.c:79: error: syntax error before "return"
C:\Users\\Desktop\struct\main.c:9: error: storage size of `comp' isn't known
Process terminated with status 1 (0 minutes, 4 seconds)
36 errors, 36 warnings
 
Volver
Arriba