Help ME!

Hello!!!

I have 2 problems, one In Topic and another Off Topic.---------------------
InTopic Prolem

SDL can’t find my cdrom drive on BeOS!!!

If I do something like this:

SDL_CD *cdrom;
cdrom = SDL_CDOpen(0);

cdrom returns me NULL!!!


OffTopic Problem

I want to create a function that take all numbers of a string.
for example:

char *string = “abc24”;

GetNumbers(string);

returns me 24.

Who can help me???
Thanks!

Otavio Pliger wrote:

InTopic Prolem

SDL can’t find my cdrom drive on BeOS!!!

this is a wild shot in the dark, but you have
called SDL_Init with SDL_INIT_CDROM ?

this is a wild shot in the dark, but you have
called SDL_Init with SDL_INIT_CDROM ?

Yes I had.

Otavio Pliger wrote:

Hello!!!

I have 2 problems, one In Topic and another Off Topic.

InTopic Prolem

SDL can’t find my cdrom drive on BeOS!!!

Since I don’t use BeOS, I can’t help with this.


OffTopic Problem

I want to create a function that take all numbers of a string.
for example:

char *string = “abc24”;

GetNumbers(string);

returns me 24.

Try doing something like this:

int GetNumbers(char *string)
{
char numberstr[80];
int i, j;

j=0;
numberstr[0] = 0; /* so
for (i=0; i<strlen(string); i++) {
if (isdigit(string[i]))
numberstr[j++] = string[i];
}
return(atoi(numberstr));
}

If you want a string of the numbers, return strdup(numberstr) instead
of atoi(numberstr).–
Rafael R. Sevilla <@Rafael_R_Sevilla> +63 (2) 4342217
Mobile Robotics Laboratory +63 (917) 4458925
University of the Philippines Diliman


OffTopic Problem

I want to create a function that take all numbers of a string.
for example:

char *string = “abc24”;

GetNumbers(string);

returns me 24.

Try doing something like this:

int GetNumbers(char *string)
{
char numberstr[80];
int i, j;

j=0;
numberstr[0] = 0; /* so
for (i=0; i<strlen(string); i++) {
if (isdigit(string[i]))
numberstr[j++] = string[i];
}
return(atoi(numberstr));
}

Something like

int GetNumbers (const char *string)
{
int returnValue;

while (*string)
{
    if (isdigit (*string))
        returnValue = returnValue * 10 + (*string++) - '0';
}
return returnValue;

}

Would be a bit faster and more robust, no?

Sean Etc.

Sean Thomas Middleditch <sean.middleditch at iname.com> wrote in message
news:394A3D63.8ECA89B at iname.com

int GetNumbers (const char *string)
{
int returnValue;

while (*string)
{
    if (isdigit (*string))
        returnValue = returnValue * 10 + (*string++) - '0';
}
return returnValue;

}

If isdigit(*string) evaluates as false, string is never incremented and you
end up with an infinite loop.–
Rainer Deyke (root at rainerdeyke.com)
Shareware action/role-playing games - http://rainerdeyke.com
"In ihren Reihen zu stehen heisst unter Feinden zu kaempfen" - Abigor

Rainer Deyke wrote:

Sean Thomas Middleditch <sean.middleditch at iname.com> wrote in message
news:394A3D63.8ECA89B at iname.com

int GetNumbers (const char *string)
{
int returnValue;

while (*string)
{
    if (isdigit (*string))
        returnValue = returnValue * 10 + (*string++) - '0';
}
return returnValue;

}

If isdigit(*string) evaluates as false, string is never incremented and you
end up with an infinite loop.

Oops, good point. Just make it into a for loop or add the string++ at the end
of the loop… (obviously I didn’t actually test this code out).

Sean Etc.

int GetNumbers (const char *string)
{
int returnValue;

while (*string)
{
    if (isdigit (*string))
        returnValue = returnValue * 10 + (*string++) - '0';
}
return returnValue;

}

If isdigit(*string) evaluates as false, string is never incremented and you
end up with an infinite loop.

he should cast the arg to isdigit to unsigned char anyway