When I compile, i get the following msg:Code:j=palabrarandom(); strcpy(pala,pal[j]);//Copies word selected randomly to pala
passing arg 2 of `strcpy' makes pointer from integer without a cast
>< I can't figure out what's wrong, plz help me!!!!
When I compile, i get the following msg:Code:j=palabrarandom(); strcpy(pala,pal[j]);//Copies word selected randomly to pala
passing arg 2 of `strcpy' makes pointer from integer without a cast
>< I can't figure out what's wrong, plz help me!!!!
JP Button
I know this will get said sooner or later but to hell with that.
Do your own homework.
Im trying to Elcura, this is why Im asking for help. My programming teacher hasn't arrived and no one knows what's wrong with it. Thus why I sought help here.
It looks like a circular reference to me, but christ I don't even know what language you are programming in.
C++,,VB,Pascal,jesuslolomz it all runs together too much >_<
I'm no fishing expert, but I don't think Strcpy can be caught using Integer bait. I don't know how much Integer costs, but I think you might as well bite the bullet and cast your line and find out.
try yelling at it
it's plain and simple C -.- forgot to mention sorry.
You can't say that unless you've never asked for help on your own work, ever.Originally Posted by Elcura
Would help if you posted more of the program. I don't even know what type that array pal is declared as, or what type pala is.
Well I didn't include the code cuz most is in spanish and I figured it wouldn't help if you couldn't understand but uh... commands are same no matter language so maybe you can help.Code:/* PRACTICA 2 MODULO 1 Laura Perez Mendoza */ #include <stdio.h> #include <string.h> #include <stdlib.h> #include <time.h> /*Prototipos*/ void print_monito(int); int palabrarandom(void); char aleatorio(); char juego(); /*Variables*/ int j,h,i,u,p; int vidas=5; char let; //Caracter ingresado por usuario char pala[101]; //Palabra a encontrar char temp[101]=""; //Temporal char pal[101]; int main() { system("clear"); printf("Este programa fue hecho, deshecho, odiado y aborrecido por Laura Perez Mendoza\n"); getchar( ); do{ printf("COLGADO :D\n\n1.- Comenzar Juego.\n2.- Salir."); scanf ("%d", &u); switch(u){ case 1: //Ejecuta el juego aleatorio(); for (h=0;h<strlen(pala);h++) //Imprime '?' de la palabra a buscar { temp[h]='?'; } printf ("\n\n"); juego(); break; case 2: exit(1); //Sale del programa default: printf ("Tienes que elegir una de las opciones!!\n"); main(); //En caso de elegir opcion incorrecta } }while(u!=2); } char aleatorio()//Elige una palabra aleatoriamente { int j; char pal[101] = {"mundo", "vertiente", "programa", "casa", "tarjeta", "cosa", "computadora", "programacion", "", "monitor", "mina", "parka", "scanner", "nieve", "powpow", "carrete", "ventana", "chao", "hola", "tarro", "mueble", "bicicleta", "chile", "hola", "musica", "pantalon", "juegos", "poker", "teclado", "auto"}; j=palabrarandom(); strcpy(pala,pal[j]);//Copia palabra a encontrar en pala }//aleatorio int palabrarandom(void) { static int firstcall=1; if(firstcall){ srand((unsigned int) time(NULL)); firstcall=0; } return (rand( )%30+1); }//random /* PRACTICA 2 MODULO 2 */ char juego() { system("clear"); printf ("Te quedan %d vidas\n", vidas); print_monito(vidas); //Imprime el monito de acuerdo a las vidas que quedan printf ("La palabra a descubrir tiene %d letras\n", strlen(pala)); printf ("Intenta adivinar, ingresa una letra\n"); for (h=0;h<strlen(pala);h++) { printf ("%c ",temp[h]);//Imprime los caracteres descubiertos, en caso contrario imprime '?' } printf ("\n"); scanf(" %c",&let); i=0; //Contador para comprobar si el jugador acierta o no for(h=0;h<strlen(pala);h++){ if (pala[h]==let) //Comprueba si algun caracter de la palabra a buscar es igual al caracter ingresado { temp[h]=let; //Copia el caracter en temp if (strcmp(pala,temp)!=0){ i++; } else{ printf("Ganaste! Felicitaciones\n"); return 0; } } } if (i>0){ juego(); //Con i mayor a 0 el juego continua } else{ vidas--; //Se descuenta una vida if (vidas==0) { printf ("\n\n"); printf ("Perdiste, se acabaron tus vidas, intentalo de nuevo.\n"); print_monito(vidas); printf ("La palabra a encontrar era: %s\n\n", pala); } else juego(); //Si aun quedan vidas, el juego continua } }//juego void print_monito(int v) //Imprime el monito { printf(" ______ \n |"); if(v<5) printf(" _L_");printf("\n |"); if(v<5) printf(" /o o\\");printf("\n |"); if(v<5) printf(" \\___/");printf("\n |"); if(v<4) printf(" |");printf("\n |"); if(v<4) printf(" --+"); if(v<3) printf("--");printf("\n |"); if(v<2) printf(" |");printf("\n |"); if(v<2) printf(" /"); if(v<1) printf(" \\");printf("\n | \n_|_ /\\/\\/\\ \n\n"); }//printmonito
lol i didn't want the whole program. just the declarations of those 2 variables.
The call to strcpy is using the global variable pal. Change the function aleatorio to be something like this:Code:char pala[101]; //Palabra a encontrar char pal[101]; ... char aleatorio()//Elige una palabra aleatoriamente { int j; char pal[101] = {"mundo", "vertiente", "programa", "casa", "tarjeta", "cosa", "computadora", "programacion", "", "monitor", "mina", "parka", "scanner", "nieve", "powpow", "carrete", "ventana", "chao", "hola", "tarro", "mueble", "bicicleta", "chile", "hola", "musica", "pantalon", "juegos", "poker", "teclado", "auto"}; j=palabrarandom(); strcpy(pala,pal[j]);//Copia palabra a encontrar en pala }//aleatorio
Also there is another syntax error which I don't really know why it's compiling at all. it should beCode:char aleatorio()//Elige una palabra aleatoriamente { int j; char pal_local[101] = {"mundo", "vertiente", "programa", "casa", "tarjeta", "cosa", "computadora", "programacion", "", "monitor", "mina", "parka", "scanner", "nieve", "powpow", "carrete", "ventana", "chao", "hola", "tarro", "mueble", "bicicleta", "chile", "hola", "musica", "pantalon", "juegos", "poker", "teclado", "auto"}; j=palabrarandom(); strcpy(pala,pal_local[j]);//Copia palabra a encontrar en pala }//aleatorio
Code:char* pal_local[101] = {"mundo", "vertiente", "programa", "casa", "tarjeta", "cosa", "computadora", "programacion", "", "monitor", "mina", "parka", "scanner", "nieve", "powpow", "carrete", "ventana", "chao", "hola", "tarro", "mueble", "bicicleta", "chile", "hola", "musica", "pantalon", "juegos", "poker", "teclado", "auto"};
I tried that and it still gave me the same error
I just compiled the following code successfully:
Are you sure you went through the correct procedure to rebuild the C file into the obj file and everything? Put some junk code that earlier up in the file that you know will fail for a different reason, then recompile and see if it gives you a different error. Just so that you can check if the compiler is even using the correct code. Then copy/paste the function above into your file and see if it works, because I just tested it on my computer and that function worked fine.Code:void f() { int j=5; char* pal_local[101] = {"mundo", "vertiente", "programa", "casa", "tarjeta", "cosa", "computadora", "programacion", "", "monitor", "mina", "parka", "scanner", "nieve", "powpow", "carrete", "ventana", "chao", "hola", "tarro", "mueble", "bicicleta", "chile", "hola", "musica", "pantalon", "juegos", "poker", "teclado", "auto"}; char pala[101]; strcpy(pala, pal_local[j]); }
the whole problem was that stupid asterisk. Ty Divisortheory, u just saved my grade.
This looks like it prints a melee Redmage. Your program fails.void print_monito(int v) //Imprime el monito
{
printf(" ______ \n |");
if(v<5) printf(" _L_");printf("\n |");
if(v<5) printf(" /o o\\");printf("\n |");
if(v<5) printf(" \\___/");printf("\n |");
if(v<4) printf(" |");printf("\n |");
if(v<4) printf(" --+");
if(v<3) printf("--");printf("\n |");
if(v<2) printf(" |");printf("\n |");
if(v<2) printf(" /");
if(v<1) printf(" \\");printf("\n | \n_|_ /\\/\\/\\ \n\n");
}//printmonito
its a hangman
No, it's obviously supposed to be someone dancing, but putting it in SMART PEOPLE SPEAK messed it up. Here, allow me to translate.Originally Posted by Raineer
"\(^_____^ "\) ( ^_L_^) "\(n_n"\) ( /o.o\) "\(n_n"\) CHA-CHA-CHA!