-
problems with tolower
Hey everyone. I'm using Slackware Linux 9.1, with gcc version 3.2.3.
The error I'm getting is:
Code:
Tools.cxx: In function `unsigned int StringToInt(const std::string&)':
Tools.cxx:33: `tolower' undeclared (first use this function)
Tools.cxx:33: (Each undeclared identifier is reported only once for each function it appears in.)
The source code for the file is:
Code:
17#include "Tools.hxx"
18
19///////////////////////////////////////////////////////////////////////////////
20// Convert the hex string to an unsigned integer
21///////////////////////////////////////////////////////////////////////////////
22unsigned int StringToInt(const string& hex)
23{
24 static char digits[] = "0123456789abcdef";
25 unsigned int result = 0;
26
27 for(unsigned int t = 0; t < hex.length(); ++t)
28 {
29 unsigned int digit = 0;
30
31 for(unsigned int s = 0; s < 16; ++s)
32 {
33 if(digits[s] == tolower(hex[t]))
34 {
35 digit = s;
36 break;
37 }
38 }
39 result = result * 16 + digit;
40 }
41 return(result);
42}
I'm not sure what's wrong here, hopefully someone here can help me out. (ps, I didn't write this code, I'm just trying to compile this so I can install a program I need for school. I haven't done any C/C++ coding for years. I'd prefer not to modify it any more then required to compile and still return the same answer)
Thanks.
-
Ok, I added #include <ctype.h>, got some warning about using out of date code, but it compiled. Got new errors on a different file though. Much more complicated ones that I don't understand at all. I'll post the entire error and source code for the new error.
Error is:
Code:
gcc -I/root/bsvc-2.1/src/Framework -O -ansi -Wall -D_G_NO_EXTERN_TEMPLATES -c xtermpipe.cxx
xtermpipe.cxx: In function `int WaitForIO(int)':
xtermpipe.cxx:34: invalid conversion from `void*' to `timeval*'
And here's the code (only put the line number indicated in the error):
Code:
///////////////////////////////////////////////////////////////////////////////
// This simple program can be used with the Motorola M68681 DUART
// to pipe input and output to an xterm.
//
// By: Bradford W. Mott
///////////////////////////////////////////////////////////////////////////////
#include <sys/time.h>
#include <sys/types.h>
#include <sys/param.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <signal.h>
int WaitForIO(int pipe_id)
{
fd_set readfds;
fd_set writefds;
fd_set exceptfds;
FD_ZERO(&readfds);
FD_ZERO(&writefds);
FD_ZERO(&exceptfds);
FD_SET(0, &readfds);
FD_SET(pipe_id, &readfds);
# ifdef _HPUX_SOURCE
select(pipe_id + 1, (int*)&readfds, (int*)&writefds, (int*)&exceptfds,
(void*)0);
# else
34 select(pipe_id + 1, &readfds, &writefds, &exceptfds, (void*)0);
# endif
if(FD_ISSET(0, &readfds))
return(0);
else
return(1);
}
int main()
{
int read_id, write_id;
system("stty -echo -echoe -echonl raw");
read_id=3;
write_id=4;
while(1)
{
if(WaitForIO(read_id))
{
char c;
read(read_id, &c, 1);
write(1,&c,1);
}
else
{
char c;
read(0, &c, 1);
if(write(write_id, &c, 1)<0)
printf("Error on write!!!\n");
}
}
}
-
You are casting zero to a void* and it expects a timeval*? What is the definition of the select() function? If it can take a null timeval then just use zero without casting.
-
Well....select isn't a function that's defined in any of the source code for this application, so I assume it's using the built-in select(). The select is regards to communicating over ports.
Incidently, this is BSVC, a 68000 assembler/simulator. So, this part is that part that simulates a DUART 68681 device. I did manage to get the code to compile by tweaking it in many places, but naturally, my tweaking must be goofy somewhere. It doesn't work properly. Where it gets funny is exactly here: opening and communicating with a simulated DUART 68681 device. So, I don't think I can change that to just a 0. I tried that. I also tried changing the void* to a timeval* just for kicks. Still won't communicate with a simulated DUART 68681.
-
The outdated code warning is probably due to the fact that you should use <cctype>, not <ctype.h>.
-
Tried #include <ctype> instead of the .h counterpart, got a "file does not exist" error on compile.
I found a site with precompiled binaries. I'm going to try those.
-
look closely, it is <cctype> not <ctype>