some c++ code

Discussion about everything. New games, 3d math, development tips...
Guest

Post by Guest »

well I fixed those errors and warning, Now I don't get none when I use wall in GCC.

Code: Select all

#include <iostream>

using namespace std;

bool isNumber(char *c)
{
    signed int len = strlen(c);
    if(len > 0)
    {
        for(int i = 0;i<len;i++)
        {
            if(!(isxdigit(c[i])))
            {
                return false;
            }
        }
        return true;
    }
    return false;
}

int main(void)
{

    char *blah = "1";
    if(isNumber(blah))
    {
        cout << "Yep" << endl;
    }
    else
    {
        cout << "Nope" << endl;
    }

    char * c;

    c = "Hello World!";

    cout << c << endl;

    system("PAUSE");

    return 0;
}
There is what I got now. What is funny is that it doesn't print out 'Hello World!', WHAT AM I DOING WRONG????
bitplane
Admin
Posts: 3204
Joined: Mon Mar 28, 2005 3:45 am
Location: England
Contact:

Post by bitplane »

well, I decided to actually compile it and run it. it works fine if you replace isxdigit for isdigit.
Submit bugs/patches to the tracker!
Need help right now? Visit the chat room
Guest

Post by Guest »

why doesn't it work for me then? you compiled in gcc with codeblocks right?
Guest

Post by Guest »

mingw
Guest

Post by Guest »

its okay, I solved it. I made a stupid mistake and forgot to set it as a console application. It was set to GUI... sorry.. thanks for the help though.
Kaeles-notlogged

Post by Kaeles-notlogged »

First of all, its bad style to have a char pointer to a string, infact, im not sure that should even work... maybe i'm wrong...
where you say char *blah = "1";
thats a string literal, which i believe is a char[], so, your creating a character array, and then pointing the *blah to the first element. Which is the same as saying char blahArray[1];
blahArray[0] = '1';
char *blah = blahArray[0];

Anyways, another thing, the for loop requires NOTHING inside the parenthesis, you could say for(;;) and it would run.
of course this would make an infinate loop, but yea.

I'm sleepy, so if any of this doesn't make sense... sorry.
:p
Post Reply