Buongiorno/buonasera.
Sto scrivendo una text-based adventure per hobby. Il programma sembra funzionare bene, se non per alcuni fattori:
1) quando premo 2 (credits) e premo 'b' per ritornare al menù, quando premo il tasto 3 (exit), rimane bloccato in un loop.
2) ci sono dei messaggi del compilatore che non ho ben capito come risolvere
qui di seguito posto il codice e i messaggi usciti:
messaggi di errore:codice:#include <stdio.h> #include <string.h> #include <stdlib.h> #include <windows.h> #define MAX_LEN 128 void red(){ HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE); int k; SetConsoleTextAttribute(hConsole, k=12); } void white(){ HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE); int l; SetConsoleTextAttribute(hConsole, l=15); } void green(){ HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE); int a; SetConsoleTextAttribute(hConsole, a=10); } int image(){ char *filename = "drago.txt"; FILE *fptr = NULL; if((fptr = fopen(filename,"r")) == NULL) { fprintf(stderr,"error opening %s\n",filename); return 1; } print_image(fptr); } void submenu2(void){ for(;;){ char choice1; system("cls"); printf("Written by Francesco\nIDE: Bloodshed Dev-C++\nProgrammed in C\nFebruary 2018\n"); printf("Press b key to come back to menu...\n>>"); scanf("%c",&choice1); if(choice1 == 'b'){ system("cls"); //image(); menu(); break;} // torna al mainmenu else printf("wrong input. try again."); } } void menu(){ int choice,i=1; image(); red(); printf("\n\t\t\tSoftware version 1.0 Beta"); green(); printf("\t\t\t All rights reserved 2018\n\n"); white(); printf("[1] Play\n"); printf("[2] Credits\n"); printf("[3] Exit\n>>"); while(i){ scanf("%d",&choice); switch(choice){ case 1: break; case 2: submenu2(); break; case 3: system("cls"); green(); printf("\n\t\t\t\t\t ***************************************\n "); red();printf("\n\t\t\t\t ***********Thanks for playing**********\n"); white();printf("\n\t\t\t\t\t ***************************************\n "); i = 0; /* loop exit */ break; default: printf("\nInvalid choice!\n>>"); break; } } return 0; } void print_image(FILE *fptr); int main(void) { menu(); return 0; } void print_image(FILE *fptr) { char read_string[MAX_LEN]; while(fgets(read_string,sizeof(read_string),fptr) != NULL) printf("%s\t\t\t\t",read_string); }
Immagine1.pngImmagine2.png
PS: vorrei implementare un modo per controllare l'input quando viene digitato un carattere al posto del numero, sapreste suggerirmi come fare?
Grazie a chiunque risponderà

Rispondi quotando