|
|
View previous topic :: View next topic |
Author |
Message |
ECACE
Joined: 24 Jul 2006 Posts: 94
|
Problem with toupper |
Posted: Wed Dec 17, 2008 1:52 pm |
|
|
I am having trouble getting toupper to work correctly. The code below works when I manually go through each char and convert it. But if I use the for loop and try to convert it, it does not work. It compiles fine, but for example if I put in "ht" which is one of the commands in lower case, I would expect to get back HT, but instead I get ht. So, it looks like you can't use a for loop for converting chars with toupper??? That doesn't sound right. Please tell me I am just doing something stupid here.
I want to be able to use the commented out for loop to do the conversion, instead I am having to do the manual: COMMAND[0] = toupper(COMMAND[0]);
Otherwise it just isn't converting it. Entering upper case returns uppercase and entering lower case returns lower case.
Also, at the begining of the program, I do have:
#device PASS_STRINGS = IN_RAM //Needed for String functions to work
and I have included the string headers:
#include <string.h> //Header file for string manipulations
#include <stdlib.h> //Header File for ascii manipulations
Code: | printf("Enter command and press <ENTER> (attributes will be next)\r\n"); //Get command and attributes in string
gets(COMMAND);
//Variables below are declared as global in the begining of the program
//char COMMAND[5]; //Holds ascii response from user in menu
//char COMMAND_TEMP[5]; //Holds ascii response from user in menu
//char ATTRIB[4]; //Holds ascii response from user in menu
//printf("\r\nhere's what I got before conversion: %c%c%c%c%c ",COMMAND[0],COMMAND[1],COMMAND[2],COMMAND[3],COMMAND[4]);
// for(i = 0 ; i < 3 ; i++ ) //Convert COMMAND_TEMP to all uppercase
// {
// COMMAND[i] = toupper(COMMAND[i]);
// }
COMMAND[0] = toupper(COMMAND[0]);
COMMAND[1] = toupper(COMMAND[1]);
COMMAND[2] = toupper(COMMAND[2]);
COMMAND[3] = toupper(COMMAND[3]);
//printf("\r\nhere's what I got after conversion : %c%c%c%c%c ",COMMAND[0],COMMAND[1],COMMAND[2],COMMAND[3],COMMAND[4]);
|
Processor = 16F690
Compiler = PCWH
Version = 4.083
Thanks in advance for any help you can give. _________________ A HW Engineer 'trying' to do SW !!! Run!!! |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Dec 17, 2008 2:41 pm |
|
|
See this thread. It has several solutions.
http://www.ccsinfo.com/forum/viewtopic.php?t=26488
Another solution is to use a temp variable:
Code: | #include <16F690.h>
#fuses INTRC_IO, NOWDT, BROWNOUT, PUT, MCLR
#use delay(clock=8000000)
#use rs232(baud=9600, xmit=PIN_B7, rcv=PIN_B5, ERRORS)
char COMMAND[5] = {"ht"};
//========================================
void main()
{
int8 i;
int8 temp;
for(i = 0; i < 3; i++)
{
temp = toupper(COMMAND[i]);
COMMAND[i] = temp;
}
printf(COMMAND);
while(1);
} |
I don't know if CCS ever fixed this bug. I don't know if anyone ever
reported it to them. |
|
|
ECACE
Joined: 24 Jul 2006 Posts: 94
|
|
Posted: Wed Dec 17, 2008 2:49 pm |
|
|
In your example then, would I need to have all menu possibilitys defined:
char COMMAND[5] = {"ht"}
...
...
...
One for every possible menu entry? If that's the case, I wouldn't want to do that. I prefer the one you had in the post:
Code: | char my_toupper(char c)
{
if(c >= 'a' && c <= 'z')
c -= 0x20;
return(c);
} |
That was quite awhile ago, I would have thought CCS would have fixed it by now. Oh well. Thanks for the code snippet. I will plug it in and see if it works. _________________ A HW Engineer 'trying' to do SW !!! Run!!! |
|
|
ECACE
Joined: 24 Jul 2006 Posts: 94
|
|
Posted: Tue Jan 06, 2009 9:28 pm |
|
|
Old post, but I have been going back and forth with CCS on this one. They have found the bug and reported back that it will be fixed in the next update. Fingers crossed and hope it works! _________________ A HW Engineer 'trying' to do SW !!! Run!!! |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|