I have a big problem. This is the header file I created to have a little terminal menu. The problem is, in function "menu" (italian name) , that when I compile it I get a warning that says "[Warning] incompatible implicit declaration of built-in function 'printf' [enabled by default]" And then if I run it it CRASHES.
#ifndef HEADER
#define HEADER
int numeroOpz = 0;
int selezON = 0;
int tasto;
struct Opzione{
char *testo;
int selez;
};
struct Opzione *opz;
void nuovaOpzione(char *testoOpz){
strcpy(opz[numeroOpz].testo, testoOpz); //Il testo dell'opzione viene copiato
opz[numeroOpz].selez = 0; //Nessuna opzione viene inizialmente selezionata
numeroOpz++;
}
void menu(){
opz[0].selez = 1;
while(tasto != 13){
int i;
for(i=0;i < numeroOpz;i++){
if(opz[i].selez == 1){
printf("||%s||\n", opz[i].testo);
}
else if(opz[i].selez == 0){
printf("%s\n", opz[i].testo);
}
tasto = getch();
switch (tasto){
case 72: //SU
if(selezON > 0){
opz[selezON].selez = 0;
opz[selezON-1].selez = 1;
selezON--;
}
else{
opz[selezON].selez = 0;
opz[numeroOpz-1].selez = 1;
}
break;
case 80: //GIU
if(selezON < numeroOpz){
opz[selezON].selez = 0;
opz[selezON+1].selez = 1;
selezON++;
}
else{
opz[selezON].selez = 0;
opz[0].selez = 1;
}
break;
default:
printf("Error\n\n\n\n");
break;
}
}
}
}
#endif
And HERE is the source file:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "Opzioni.h"
int main(){
nuovaOpzione("Ciao");
nuovaOpzione("Bellaaa");
nuovaOpzione("Hey");
menu();
getch();
return 0;
}
I'm just getting crazy, and yes, I searched a lot for help in other questions... Thanks for helping if you do! :P
btw: the strcpy function in "nuovaOpzione" is a warning as well, but yolo...
Jens is right about the printf warning.
For the crashing, based on your program, you need an array for opz
, not a pointer.
struct Opzione opz[1000];