I am trying to use a loop so that the program will be constantly running. Its suppose to be a "mini karaoke system". However, after I call for the function start at the Main Function, the function start will check the username and compare to the ones in the array. Afterwards it should return if the username already exists or not, and then start the loop from the beginning again from zero. However, for some reason it will start the loop, call function Start and execute entirely without the user's input.
18102314@comunix:~$ vi karakoke2.c
18102314@comunix:~$ vi karaoke2.c
#include <time.h>
#include <stdbool.h>
#include <string.h>
char usern[5][6] = { "lol", " ", " ", " ", " "};
int roomuse =0, bl = 0;
void menu(){
printf("printei");
}
int gtime(){
clock_t ttime;
return ttime;
}
int checkName(char name[] /*, char usern[5][6]*/){
int i;
for ( i = 0; i < 6; i++){
if(strcmp(name, usern[i]) == 0){
printf("This username already exists. Please try again. \n");
return 0 ;
break;
}
else{ printf("return 4");
return 1; break; }
} }
int start(/*char usern[5][6]*/){
bl = 1;
char ans, name[6];
printf("Welcome, did you reserve a room already? (Y/N)");
scanf("%c",&ans);
if(ans == 'N'){
printf("Please enter a username: (Max 6 characters) ");
scanf("%s", &name);
if( checkName(name, usern)==1){
menu(); printf(" return 3"); return 0; }
else{ printf("return 2");
bl = 0;
return 0; } }
else {printf(" return 1" ); menu(); return 0;}
}
int main(void){
/*char ans, usern[5][6] = { "lol", " ", " ", " ", " "}, name[6];*/
printf("%d \n", gtime());
Output:
Welcome, did you reserve a room already? (Y/N) N Please enter a username: (Max 6 characters) lol This username already exists. Please try again. return 2Welcome, did you reserve a room already? (Y/N) return 1printeiWelcome, did you reserve a room already? (Y/N)
Expected Outuput:
Welcome, did you reserve a room already? (Y/N) N Please enter a username: (Max 6 characters) lol This username already exists. Please try again. return 2 Welcome, did you reserve a room already? (Y/N)