deceptikon 1,790 Code Sniper Team Colleague Featured Poster

0xFEEEFEEE is used to mark freed memory in Visual C++. You're using a dangling pointer after deleting it.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Have you done anything? This is clearly homework, and our rules state that you must provide proof of effort if you want help.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Actually, since the questions are of a more technical nature and concerning the development of a web site, I don't think Business Exchange is an appropriate location. This location is probably fine.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

But my doubt was that since the value of 0.1 shown above is slightly greater than 0.1 then why does the addition yield a value less than 1.

You say you read the article, but then ask a question that belies your assertion. A combination of inaccuracy at higher precisions and arithmetic rounding is why you're getting unexpected results. Read the article again, and this time actually try to understand it.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

cin.ignore(cin.rdbuf()->in_avail(),'\n');

There's no guarantee that in_avail() will give you a meaningful value. In fact, GCC always returns 0 by default. The correct way to use ignore() would be asking for up to the maximum possible stream buffer size:

cin.ignore(numeric_limits<streamsize>::max(), '\n');

There's a sticky that highlights all of the issues and potential solutions. You should read it.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

would jephthah's code work with outputting to the SAME file?

Not as-is. To be completely safe you'd want to write to a temporary file first. Then delete the original and rename the temporary to the original. Reading from and writing to the same file line by line, if it works at all due to file locking, would be very likely to corrupt subsequent reads.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Your question is nonsensical. Please elaborate.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

There's some edge cases that could make it somewhat complex.

Yes, but they have nothing to do with long lines. ;)

Mostly because you could have lines bigger than your buffer.

Actually, this is a good place for an extended fgets() that isn't restricted by a buffer size:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

/*
    @description: 
        Reads a string from the given input stream up to and
        including one of the characters in a string of delimiters.
    @return:
        The length of the final string.
    @notes:
        The result string must be released with free() from stdlib.h.
*/
size_t readline(FILE *in, char **s, const char *delim)
{
#define READLINE_CHUNK 16

    size_t capacity = 0, size = 0; /* Buffer sizing */
    char *dst = NULL, *temp;       /* Buffer contents */
    int ch, done = 0;              /* Character processing */

    while (!done) {
        /* Resize with an extra chunk if necessary */
        if (size == capacity) {
            capacity += READLINE_CHUNK;

            if (!(temp = (char*)realloc(dst, capacity + 1)))
                break;

            dst = temp;
        }

        /* Fill in the newest chunk with string data */
        while (!done && size < capacity) {
            if ((ch = getc(in)) != EOF)
                dst[size++] = (char)ch;

            done = (ch == EOF || strchr(delim, ch));
        }
    }

    /* Finalize the string */
    if (dst)
        dst[size] = '\0';

    *s = dst; /* Save the string */

    return size;

#undef READLINE_CHUNK
}

As far as edge cases go, I'd be more worried about true edge cases for comments. …

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Was it that long ago? I feel old. :(

It's been less than a year (we made the switch in March 2012). But you're probably also old, which contributes to feeling old. ;D

diafol commented: Old? I'll have you know I'm still wearing short trousers! +0
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

C: A Reference Manual and The C Programming Language both have reasonably accessible reference parts. But you can get the same result for the most part with a Google search.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Do I recall that you used to be able to do this? In profile, you could click on the avatar and if a member had uploaded a pic of themselves, that would show? Or did I dream it?

Yup, you used to be able to add a profile picture as well as an avatar. We didn't bring that feature over when switching from vBulletin though.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1124.pdf

But be forewarned: if you're a beginner to C then you'll likely find the standard obtuse and unhelpful. It's written for compiler writers, not every day users of the language.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

You've stumbled on one of the tricky points of mixing signed and unsigned values. The result of the sizeof operator is unsigned, but d is signed and negative. You can just pretend the comparison looks like this, because that's what actually happens:

for (d = -1; (unsigned)d <= (TOTAL_ELEMENTS - 2); d++)

Given that little tidbit, it's easy to see why the loop doesn't execute, because -1 when converted to unsigned will be a huge value, far greater than TOTAL_ELEMENTS - 2. This is due to the rule of unsigned wrapping. When you go negative, the value wraps around from the largest value.

One possible fix is to force both parts of the comparison to be signed:

for (d = -1; d <= (int)(TOTAL_ELEMENTS - 2); d++)

Another is to avoid starting at -1 in the first place. The following is a conventional counted loop setup that starts at 0 and goes until N-1. It's highly recommended:

for (d = 0; d < TOTAL_ELEMENTS; d++)
    printf("%d\n", array[d]);
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

corect me if i'm wrong

Well, that's not how INPUT_RECORD is defined, but as a concept for what you want to do it's fine. If you're interested, INPUT_RECORD is defined like this:

typedef struct _INPUT_RECORD {
    WORD EventType;
    union {
        KEY_EVENT_RECORD KeyEvent;
        MOUSE_EVENT_RECORD MouseEvent;
        WINDOW_BUFFER_SIZE_RECORD WindowBufferSizeEvent;
        MENU_EVENT_RECORD MenuEvent;
        FOCUS_EVENT_RECORD FocusEvent;
    } Event;
} INPUT_RECORD;

And KEY_EVENT_RECORD looks like this:

typedef struct _KEY_EVENT_RECORD {
    BOOL bKeyDown;
    WORD wRepeatCount;
    WORD wVirtualKeyCode;
    WORD wVirtualScanCode;
    union {
        WCHAR UnicodeChar;
        CHAR   AsciiChar;
    } uChar;
    DWORD dwControlKeyState;
} KEY_EVENT_RECORD;

The other members of the union look like this:

typedef struct _MOUSE_EVENT_RECORD {
    COORD dwMousePosition;
    DWORD dwButtonState;
    DWORD dwControlKeyState;
    DWORD dwEventFlags;
} MOUSE_EVENT_RECORD;

typedef struct _WINDOW_BUFFER_SIZE_RECORD {
    COORD dwSize;
} WINDOW_BUFFER_SIZE_RECORD;

typedef struct _MENU_EVENT_RECORD {
    UINT dwCommandId;
} MENU_EVENT_RECORD;

typedef struct _FOCUS_EVENT_RECORD {
    BOOL bSetFocus;
} FOCUS_EVENT_RECORD;

Not overly complicated, but you should be able to see the nested structure. The intended usage isn't quite what you're thinking of, but the classes you've derived from it should work for your purpose.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

i've tryed using structs but there's a catch

The real catch is that structs are classes.

The first question i'm asking is there a better way to handle this action other than classes

No.

The secon question is there any way to dinamicly create a variabile better yet a variabile that's created in a class whit the name given in a function(variabile_name) and a value (variabile_value)

No. You can store the "variables" in a map using the name for your key:

some_class.map_of_nested_class["Variable"].doSomething();

But the type for "Variable" has to exist itself as a class, it won't be dynamically generated. C++ is not well suited to the kind of dynamic/variant programming style you seem to want.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

is it safe/good programming structure to declare it outside the main as below?

Global variables are generally perceived as poor practice because anything and everything can touch them. This makes debugging exceptionally difficult. It's recommended that you pass the variables around as function arguments if possible:

void createAccount(vector<bankAccount>& vAccounts)
{
    vAccounts.push_back(bankAccount());
}

int main()
{
    vector<bankAccount> vAccounts;

    ...

    createAccount(vAccounts);

    ...
}
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Child implicitly calls the default constructor for Parent, but Parent doesn't have a default constructor because you explicitly defined a single argument constructor. The quickest solution would be to modify your current constructor to have a default argument such that it also acts as a default constructor:

Parent(double n = 0)                                      
{
    num = n;
}
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

That's like asking how to make an operating system. Antivirus applications aren't trivial, so your best bet would be to find an open source antivirus project and study how it works.

And nobody will give you source code because it would be hideously long.

AndreRet commented: indeed, well said +12
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

The problem I am having is creating objects inside of the program, is this even possible?

Yes, of course it's possible. Otherwise objects would be nigh useless.

Is this above even possible?

Not without enough difficulty to make it impractical. What you probably want are unnamed objects, or a collection of them in this case. For that there are collection classes such as std::vector. For example:

#include <iostream>
#include <vector>

class bankAccount
{
public:
    bankAccount() : accNumber(lastAccNumber++), accBalance(0) {};
    int getNumber()  const { return accNumber; }
    int getBalance() const { return accBalance; }
    void plusBalance(int amountAdded) { accBalance = accBalance + amountAdded; }
    void minusBalance(int amountMinus) { accBalance -= amountMinus; }
private:
    int accNumber;
    int accBalance;
    static int lastAccNumber;
};

int bankAccount::lastAccNumber = 1;

int main()
{
    std::vector<bankAccount> accounts;

    // Create 10 accounts
    for (int i = 0; i < 10; ++i)
        accounts.push_back(bankAccount());

    // Credit the 3rd account
    accounts[2].plusBalance(123);
    accounts[2].plusBalance(5);
    accounts[2].plusBalance(11);

    // Get current info for the 3rd account
    std::cout<<"Account #"<< accounts[2].getNumber() <<'\n'
             <<"Balance: "<< accounts[2].getBalance() <<'\n';
}

You can learn more about std::vector here.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Lucaci Andrew i've been using that method for a while now but i'm not comfident that this method is the best one to use.

That's the only way you're going to get the syntax you want, given that the membership operator can't be overloaded. Are you sure that the game is interpreting C++? Usually those console commands are a DSL.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

how to resets the transactioncount zero in child class checkaccount

How about a public Reset() member function that does it?

void checkaccount::Reset()
{
    transactioncount = 0;
}

Resetting that count seems off to me, since presumably it's internal data that the caller shouldn't have access to, but I'm not familiar with your requirements.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Call it a streach, but can't you use 2 combobox one has main items and second will contain submenu items

That's how I've done parent-child selection lists before, but the data binding is a bitch to get right. I imagine these days that solution seems outdated though.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Start by reading up on how to parse command line arguments. Then see what you can come up with based on what you learn, and if you have any specific problems or questions, don't hesitate to ask.

It's very difficult to tell you how to do this without making assumptions about your level and without writing a complete tutorial on the subject (far more than is justified for a forum post).

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

You've pretty much described the use case for static data members:

#include <iostream>

class BankAccount {
public:
    void Credit(double amount)
    {
        std::cout<<"Crediting "<< amount <<'\n';
        ++transactions;
    }

    void Debit(double amount)
    {
        std::cout<<"Debiting "<< amount <<'\n';
        ++transactions;
    }

    int Transactions() const { return transactions; }
private:
    static int transactions;
};

int BankAccount::transactions = 0;

int main(void)
{
    BankAccount acct;

    std::cout<<"Transactions: "<< acct.Transactions() <<'\n';
    acct.Credit(123.45);
    acct.Debit(23.23);
    acct.Debit(1.23);
    std::cout<<"Transactions: "<< acct.Transactions() <<'\n';
}
phorce commented: I like this answer. +6
deceptikon 1,790 Code Sniper Team Colleague Featured Poster
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

http://en.wikipedia.org/wiki/Non-breaking_space

A little digging suggests something like variable.replace(/\xc2\xa0/g, '') as a solution with the way I assume you're handling encodings. You may need to tweak the code a bit as I'm not super hip with Javascript.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Well, you could derive a solution directly from the wording of the definition. First count the number of nodes to get a value for n, then determine the depth of the tree so you know what the last level is, finally do a level order traversal and check at the end of each level whether the size is 2^n or it's the last level.

This breaks the problem down into three smaller problems:

  1. Counting the nodes in a tree.
  2. Finding the depth of a tree.
  3. Performing a level order traversal and counting nodes on each level.
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Is the include directory where Car.h lives in your search paths? What's the directory structure of your project?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

But when i compile and run it, it gives me errors.

What are the errors? Seriously, would you go to an auto mechanic and say "something's wrong" and expect them to find the problem you're thinking of?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

To save on time we are setiing the timer tick event to occur every 5 sec which is equal to 1 hour.

Is this a simulation or something?

only happens on the first instance of the tick event

You're using DateTime.Now as the starting point for the hour in all cases, which means the time will never be more than one hour beyond the current hour. You should be using the last stored time and extract the hour for update. Maybe something like this:

DateTime lastTime = DateTime.Parse(labelTime.Text);

labelTime.Text = new TimeSpan(
    lastTime.Hour + 1, 
    lastTime.Minute, 
    lastTime.Second).ToString();
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Not with the standard Windows Forms combo box control. You'd need to extend and modify it to add sub menus, or use a third party control that already does this. You might have that kind of control with WPF, but I'm not familiar with WPF, so someone else will need to chime in on that.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

The towers of Hanoi program is a very common homework exercise. Please provide some proof of effort if you want any help. Whether you intended it to or not, your question reads like "gimme gimme gimme" with no intention of doing any work.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Oh ok so would it just be like:

No, not really. You're summing the contents of the array, so num should control the loop and index a for the value. You also need to return the average rather than store it in a local variable:

double tableAverage(double a[], int num)
{
    double sum = 0;
    int count = 0;

    while (count < num) {
        sum += a[count];
        ++count;
    }

    return sum / num;
}

I also included two convenience operators for adding and assigning, the += and ++ operators. They do basically the same thing you were doing before, just shorter. Another option for making the code more concise, conventional, and readable might be using a counted loop and changing the variable names a bit:

double tableAverage(double a[], int size)
{
    double sum = 0;

    for (int i = 0; i < size; ++i)
        sum += a[i];

    return sum / num;
}

That might not seem more readable to a beginner, but experienced C programmers will have an easier time with it than the while loop and unconventional variable names, which cause us to stumble a bit in terms of pattern matching.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

You have a number of problems in the code. Please be patient for a moment while I list them out.

'#include<conio.h>'

Use of this library should be avoided except in cases where it really does offer the best solution (which is extremely rarely).

printf("How long is the string:");

This prompt is not guaranteed to be displayed before scanf() blocks for input, so the user might be greeted by nothing more than a blinking cursor and no hint of what to do. The reason for that is C only guarantees three times when the output buffer gets flushed to the destination device (the screen in this case):

  1. When the buffer is full.
  2. When a newline character is sent.
  3. When fflush() is called on the output stream.

In the case of #1 you have no control over it because the size of the buffer and its current contents are unknown. #2 isn't ideal for prompts because then you'd have a prompt on one line and the blinkie cursor on the next line; it's kind of ugly. So the only option for prompts is using fflush:

printf("How long is the string: ");
fflush(stdout);

I'm flushing stdout because that's the stream object that printf writes to.

scanf("%s",&num);

num is not a string, you need to use the %d specifier. Also, it's critically important to check user input for failure. scanf() returns the number of successful conversions, which in general if that number corresponds to the …

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

this.Close() and also this.Dispose() causes an exception.

Then I'd wager you have a problem in your cleanup code. Environment.Exit() probably works because it terminates the process in an unclean way for form applications. I'd further speculate that Application.Exit() fails as well, because it cleanly ends the application.

In other words, your code is broken. Trace the exception and find out where it's coming from, then fix the problem. The closing issue will be resolved as well.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

That's much more helpful. Now it's obvious that you're not properly qualifying the namespace that XMLElement lives in:

tinyxml2::XMLElement* GetElement(std::string name);

And you still need to include <string> for std::string.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Well, sadly i't ain't just a wrong header.

Well then you'll need to be more specific. What compiler, what OS, give us your exact code in a compact form so that we can reconstruct your project. Because from what you posted, the only answer is "include the correct header".

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Even when i do include the header it still errors.

Then it's the wrong header.

Oh, and there is no error about an unrecognized type ;-)

Clearly you and I are reading different errors, because the one you posted says exactly that. "expected constructor, destructor, or type conversion" means a recognized type is expected but wasn't provided.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

You need to include a header with the declaration of XMLElement (not to mention <string> for the std::string class). Just because the library is linked doesn't mean the compiler won't complain about unrecognized types.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

By perfectly balanced do you mean a complete tree? A full tree? Merely a height balanced or weight balanced tree? The algorithm is different for each. Typically what's meant is height balance, or what would be the desired end structure maintained an AVL tree.

A recursive algorithm presents itself immediately when you think about measuring the height of each subtree and comparing them:

is_balanced(tree)
    balanced = true
    height_diff = 0

    if not empty(tree)
        balanced = is_balanced(tree.left) and is_balanced(tree.right)
        height_diff = abs(height(tree.left) - height(tree.right))
    end if

    return empty or (balanced and height_diff <= 1)
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

You have to be really careful when treating strings as raw memory and vice versa because raw memory can have legit embedded null characters. The problem you're having is basically you stop processing on a null when you should keep going. I made a few changes that fix your problem. Compare and contrast to see what I did and try to figure out why I did it:

#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>

typedef struct{
    int16_t port;
    int16_t priority;
    char * ip;
    char * code;
}  t_file_package;

typedef struct {
    int8_t packageType;
    int32_t length;
    char *data;
}  t_stream;

t_stream * package_file_serializer(t_file_package *self)
{
    t_stream *stream = malloc(sizeof(t_stream));
    int32_t offset = 0 , tmp_size = 0;

    stream->data = malloc(strlen(self->ip) + 1 + sizeof(int16_t) + sizeof(int16_t) + strlen(self->code) + 1);

    memcpy(stream->data + offset, &self->port, tmp_size = sizeof(int16_t));

    offset = tmp_size;
    memcpy(stream->data + offset, &self->priority, tmp_size = sizeof(int16_t));

    offset += tmp_size;
    memcpy(stream->data + offset , self->ip , tmp_size = strlen(self->ip)+1);

    offset += tmp_size;
    memcpy(stream->data + offset , self->code , tmp_size = strlen(self->code)+1);

    stream->packageType = 1;
    stream->length = offset + tmp_size;

    return stream;
}

t_file_package * package_file_deserializer(t_stream *stream)
{
    t_file_package *self = malloc(sizeof(t_file_package));
    int32_t offset = 0, tmp_size = 0;

    memcpy(&self->port, stream->data + offset, tmp_size = sizeof(int16_t));

    offset = tmp_size;
    memcpy(&self->priority, stream->data + offset, tmp_size = sizeof(int16_t));

    offset += tmp_size;
    tmp_size = strlen(stream->data + offset) + 1;
    self->ip = malloc(tmp_size);
    memcpy(self->ip, stream->data + offset, tmp_size);

    offset += tmp_size;
    tmp_size = strlen(stream->data + offset) + 1;
    self->code = malloc(tmp_size);
    memcpy(self->code, stream->data + …
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

atoi() should work. Note that the problem here is not converting to hexadecimal per se, it's converting a string to an integer. Once in memory there's no difference between decimal and hexadecimal, it's all just bit patterns. The difference in representation is for human consumption, so it's all about strings. If you have a string "64357", you don't need to worry about hexadecimal, just turn it into a decimal integer with the formula:

for each digit
    result = 10 * result + digit

Then the value is in memory and when you display it, that's when it needs to be converted to a hexadecimal string:

#include <stdio.h>

unsigned str_to_decimal(const char *s)
{
    const char *digits = "0123456789";
    int result = 0;

    for (; *s; ++s) {
        int digit_val;

        /* Find the index of the digit (equivalent to its numeric value) */
        for (digit_val = 0; digits[digit_val]; ++digit_val) {
            if (digits[digit_val] == *s)
                break;
        }

        /* Only process recognized digits */
        if (digits[digit_val])
            result = 10 * result + digit_val;
    }

    return result;
}

int main(void)
{
    printf("0x%X\n", str_to_decimal("64357"));
}

Or, by taking advantage of the guaranteed relationship of the decimal digits in all character sets (ie. they're contiguous), you can simplify by removing the search and using an arithmetic transformation:

#include <stdio.h>
#include <ctype.h>

unsigned str_to_decimal(const char *s)
{
    int result = 0;

    for (; *s; ++s) {
        /* Only process recognized digits */
        if (isdigit((unsigned char)*s))
            result = 10 * result + (*s - …
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Would it be wrong of me to assume that you'd benefit from looking at an implementation of a standard library function that can handle this? If so, I can shrink it down to the necessities and explain what's going on.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

You can undo it, no worries. ;)

pritaeas commented: Figured it out after posting. +0
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Are precompiled headers enabled for the project? That's what stdafx.h is, all of the standard headers precompiled into one so that you don't have to include them as needed. The down side is that your code is closely tied to the compiler. Ideally you'd disable that feature and include <iostream>.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

you tell me this is the question given to me

I still don't see any problem. By "manual assignment using initializer", your teacher means this:

int matrix[5][5] = {
    { 0,  1,  1,  1, 1},
    {-1,  0,  1,  1, 1},
    {-1, -1,  0,  1, 1},
    {-1, -1, -1,  0, 1},
    {-1, -1, -1, -1, 0},
};

Normalizing negative numbers to -1 and positive numbers to 1 strikes me as a completely viable solution. An if statement is clearly the simplest way to do that, though you could certainly use a clever expression to work out the normalization:

#include <stdio.h>
#include <stdlib.h>

int main(void)
{
    int i;

    for (i = 10; i >= -10; --i) {
        if (i != 0)
            printf("%d\n", i / abs(i));
        else
            printf("%d\n", i);
    }

    return 0;
}

My answer wasn't intended to be "obviously witty". It's important to recognize simple solutions to simple problems and apply them when there's really no reason to be clever. Clever code is obtuse code, and obtuse code is difficult to maintain.

zeroliken commented: Agree :) +9
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

@deceptikon its due in like 5 hours dude.

Whose fault is that? Yours. Please answer my question (why does the if statement solution not work?) if you want me to suggest other possible solutions. I'm not going to just list different ways of doing the same thing until you see one you like.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I notice you're exceptionally impatient. What's wrong with my answer?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Do you know how to write an if statement? There are three cases:

if (number == 0)
    printf("0");
else if (number < 0)
    printf("-1");
else /* number > 0 */
    printf("1");

Easy peasy.