Alhazred Posted August 7, 2004 Share Posted August 7, 2004 (edited) I have written this code ? ?char * UserInput(int max) { ? ?BOOL EndInput = TRUE; ? ?unsigned int Count; ? ?int Count2 = 0, Count3 = 0, cursore = 0; ? ?char AllowedCh[] = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', '\0'}; ? ?char AllowedNum[] = {'1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '\0'}; ? ?char *Buff; ? ?char Current = ' '; ? ?char provvisorio[2]; ? ?char *definitivo; ? ?Buff = (char *) malloc((max + 1)); ? ?definitivo = (char *) malloc((max + 1)); ? ?Buff[0] = '\0'; ? ?definitivo[0] = '\0'; ? ?while(EndInput) ? ?{ ? ? ? ?provvisorio[Count3] = getch(); ? ? ? ?definitivo = strupr(provvisorio); ? ? ? ?definitivo[Count3 + 1] = '\0'; ? ? ? ?Current = definitivo[Count3]; ? ? ? ?switch(Current) ? ? ? { ? ? ? ? ? case 13: EndInput = FALSE; ? ? ? ? ? ? ? ? ? ? ? ?Buff[Count2] = '\0'; ? ? ? ? ? ? ? ? ? ? ? ?break; ? ? ? ? ? case 8: Buff[Count2] = '\0'; ? ? ? ? ? ? ? ? ? ? ? if(cursore > 0) ? ? ? ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? ? ? ? printf("\b \b"); ? ? ? ? ? ? ? ? ? ? ? ? ? Count2--; ? ? ? ? ? ? ? ? ? ? ? ? ? Buff[Count2] = '\0'; ? ? ? ? ? ? ? ? ? ? ? ? ? cursore--; ? ? ? ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? ? ? ? break; ? ? ? ? ? ?/*function keys exclusion*/ ? ? ? ? ? ?case(0+65): break; ? ? ? ? ? ?case(0+66): break; ? ? ? ? ? ?case(0+67): break; ? ? ? ? ? ?case(0+68): break; ? ? ? ? ? ?case(0+69): break; ? ? ? ? ? ?case(0+70): break; ? ? ? ? ? ?case(0+71): break; ? ? ? ? ? ?case(0+72): break; ? ? ? ? ? ?case(0+73): break; ? ? ? ? ? ?case(0+74): break; ? ? ? ? ? ?/****************/ ? ? ? ? ? ?default: if(max == 1) ? ? ? ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? ? ? ? for(Count = 0; Count < strlen(AllowedCh); Count++) ? ? ? ? ? ? ? ? ? ? ? ? ?{ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?if(Current == AllowedCh[Count] && (Count2 < max)) ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?{ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? printf("%c", Current); ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? Buff[Count2] = Current; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? Count2++; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? cursore++; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?} ? ? ? ? ? ? ? ? ? ? ? ? ?} ? ? ? ? ? ? ? ? ? ? ? ? ?break; ? ? ? ? ? ? ? ? ? ? ?} ? ? ? ? ? ? ? ? ? ? ?else ? ? ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? ? ? for(Count = 0; Count < strlen(AllowedNum); Count++) ? ? ? ? ? ? ? ? ? ? ? ?{ ? ? ? ? ? ? ? ? ? ? ? ? ? ?if(Current == AllowedNum[Count] && (Count2 < max)) ? ? ? ? ? ? ? ? ? ? ? ? ? ?{ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?printf("%c", Current); ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?Buff[Count2] = Current; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?Count2++; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?cursore++; ? ? ? ? ? ? ? ? ? ? ? ? ? ?} ? ? ? ? ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? ? ? ? ? break; ? ? ? ? ? ? ? ? ? ? } ? ? ? ?} ? ?} ? ?return Buff; } //End UserInput I'm trying to allow the users to type a lower case char, the function provides to change it in uppercase and accept it as input. However, this code doesn't do that, how have I to change it? Edited August 7, 2004 by Alhazred Link to comment Share on other sites More sharing options...
0 Alhazred Posted August 7, 2004 Author Share Posted August 7, 2004 The problem seems to be the code to exclude function keys, if I remove it, the program works... so have you sone suggestion about how to recognize if a function key or a char key is pressed? How to do in my code? Example, if I press F7 it will input A. I don't want this! Link to comment Share on other sites More sharing options...
Question
Alhazred
I have written this code
? ?char * UserInput(int max) { ? ?BOOL EndInput = TRUE; ? ?unsigned int Count; ? ?int Count2 = 0, Count3 = 0, cursore = 0; ? ?char AllowedCh[] = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', '\0'}; ? ?char AllowedNum[] = {'1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '\0'}; ? ?char *Buff; ? ?char Current = ' '; ? ?char provvisorio[2]; ? ?char *definitivo; ? ?Buff = (char *) malloc((max + 1)); ? ?definitivo = (char *) malloc((max + 1)); ? ?Buff[0] = '\0'; ? ?definitivo[0] = '\0'; ? ?while(EndInput) ? ?{ ? ? ? ?provvisorio[Count3] = getch(); ? ? ? ?definitivo = strupr(provvisorio); ? ? ? ?definitivo[Count3 + 1] = '\0'; ? ? ? ?Current = definitivo[Count3]; ? ? ? ?switch(Current) ? ? ? { ? ? ? ? ? case 13: EndInput = FALSE; ? ? ? ? ? ? ? ? ? ? ? ?Buff[Count2] = '\0'; ? ? ? ? ? ? ? ? ? ? ? ?break; ? ? ? ? ? case 8: Buff[Count2] = '\0'; ? ? ? ? ? ? ? ? ? ? ? if(cursore > 0) ? ? ? ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? ? ? ? printf("\b \b"); ? ? ? ? ? ? ? ? ? ? ? ? ? Count2--; ? ? ? ? ? ? ? ? ? ? ? ? ? Buff[Count2] = '\0'; ? ? ? ? ? ? ? ? ? ? ? ? ? cursore--; ? ? ? ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? ? ? ? break; ? ? ? ? ? ?/*function keys exclusion*/ ? ? ? ? ? ?case(0+65): break; ? ? ? ? ? ?case(0+66): break; ? ? ? ? ? ?case(0+67): break; ? ? ? ? ? ?case(0+68): break; ? ? ? ? ? ?case(0+69): break; ? ? ? ? ? ?case(0+70): break; ? ? ? ? ? ?case(0+71): break; ? ? ? ? ? ?case(0+72): break; ? ? ? ? ? ?case(0+73): break; ? ? ? ? ? ?case(0+74): break; ? ? ? ? ? ?/****************/ ? ? ? ? ? ?default: if(max == 1) ? ? ? ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? ? ? ? for(Count = 0; Count < strlen(AllowedCh); Count++) ? ? ? ? ? ? ? ? ? ? ? ? ?{ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?if(Current == AllowedCh[Count] && (Count2 < max)) ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?{ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? printf("%c", Current); ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? Buff[Count2] = Current; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? Count2++; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? cursore++; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?} ? ? ? ? ? ? ? ? ? ? ? ? ?} ? ? ? ? ? ? ? ? ? ? ? ? ?break; ? ? ? ? ? ? ? ? ? ? ?} ? ? ? ? ? ? ? ? ? ? ?else ? ? ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? ? ? for(Count = 0; Count < strlen(AllowedNum); Count++) ? ? ? ? ? ? ? ? ? ? ? ?{ ? ? ? ? ? ? ? ? ? ? ? ? ? ?if(Current == AllowedNum[Count] && (Count2 < max)) ? ? ? ? ? ? ? ? ? ? ? ? ? ?{ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?printf("%c", Current); ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?Buff[Count2] = Current; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?Count2++; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?cursore++; ? ? ? ? ? ? ? ? ? ? ? ? ? ?} ? ? ? ? ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? ? ? ? ? break; ? ? ? ? ? ? ? ? ? ? } ? ? ? ?} ? ?} ? ?return Buff; } //End UserInputI'm trying to allow the users to type a lower case char, the function provides to change it in uppercase and accept it as input.
However, this code doesn't do that, how have I to change it?
Edited by AlhazredLink to comment
Share on other sites
1 answer to this question
Recommended Posts