deceptikon 1,790 Code Sniper Team Colleague Featured Poster

if i use "%lf" in printf will it work ?

Only if you're compiling as C99 or later, otherwise %lf is an unsupported format specifier and you invoke undefined behavior.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

then why "%f" in printf ? why not "%lf" ?

Because a float value will be automagically converted to double in a variable length argument list. There's no need for both %f and %lf because there's no difference after that conversion. However, C99 added redundant support for %lf to printf() because so many people were confused that scanf() and printf() didn't have identical rules.

And before you ask, no, a pointer to float is not converted to a pointer to double in a variable length argument list. So I'm not contradicting myself.

nitin1 commented: ;) well explained +2
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

You mistyped the code from the book. The format string for double in scanf() is "%lf", with a lower case L, not 1. For printf() it's just "%f". Adding 1 to either of them introduces a field width, which you probably don't want.

ulrik m. commented: Thank you very much, it works +0
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I mean, something that explains theroes very well to the bottom (in short) and cover needed areas in and updated with good questions and answers to them.

That describes just about any recommended book, and all of the ones you listed. I'm dead serious when I say just take a look at all of them in the bookstore and pick the one that feels most comfortable to you.

I don't think Aceelerated c++ covers C++11? is that a problem?

It's not a problem. As far as I'm aware, there aren't any good books out that cover C++11 in any meaningful way. Most of the significant features are what I would consider to be advanced anyway, and have no business being covered in a beginner book.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

when I read it how can I find out there was an endline or not ?

How do you plan to use that information once you get it? That will somewhat determine what method you use. For example, you can run through the file character by character and look for '\n' to answer the simple question of whether a newline is present, but that may not be conducive to whatever you plan to do afterward.

Well if you use getline() it will read in everything in the file until it reaches a newline.

Until it reaches a newline or end-of-file (or an error occurs). So you'd need to check the stream state to be sure that the line ended with '\n' and not EOF.

NathanOliver commented: Thanks for the clarification +10
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Why not get rid of down voting altogether? In reality, and has happened, someone could down vote out of malice, or because they don't know what they are talking about.

Any feature can be abused. Should we punish everyone for the actions of one or two outliers? Concerning the type of abuse you're thinking of, I can remember less than five instances of the same behavior for both voting and reputation in the last seven or eight years. While it's painful for the victims, the number of abuses of the system are vanishingly small compared to the number of legitimate uses.

Why not have a complaints forum, with a moderator that deals with situations in a sincere manner. It has to be sincere too, because if it isn't then there will be a real loss of face and credibility, and more cross-forum "bar brawls". If a user Complains in any forum other than the 'complaints forum, their post can be moved to it and be dealt with suitably. People who have a genuine complaint are looking for a peaceful resolution, and don't mind where it is done as longas justice is seen to be done, or whatever. Trolls would just want to make personal attacks, which is bad enough, but they also do it without any justifiable reason.

I'm not sure I see the benefit of that. If the "complaint" is about a suspected rule violation the post should be reported using our reporting system. If …

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

looks like its still not producing the results needed.

Then start up a debugger and trace through the function. Or you can add debug prints that tell you what each value is at key points in the algorithm. It's important to learn how to debug your code, because someone won't always be around to tell you what the problem is and how to fix it. ;)

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I'd use a chat feature for non-help related discussions but I doubt I'd use it to help someone except in rare circumstances.

My experience with the IRC channel is that it's mostly random chat with a slightly technical bent (obviously, because we're techies). Sometimes questions were brought up and answered if it wasn't too time consuming and didn't require detailed examples such as code. For the complex questions or ones where an answer would take more than a couple of sentences, they were directed to the forums. However, often questions encouraged a tangent of discussion that kept things moving.

By far the most entertaining instances of IRC chatting was when crazies from the forum (cough TkTkorrovi cough) came in to rant and we egged them on for lulz. ;)

Reverend Jim commented: Hi-tech fishing :-P +0
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

so what should i do about line 10

Fix line 8.

but at line 102 it is saying 102 C++ forbids comparison between pointer and integer..

That's basically the same thing I said. i is an int and numemps is an array. You can't compare the two because it's not meaningful. Change numemps to an int just like in print_unluckies(); you clearly know how it's supposed to work because you've done it correctly in another function.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Line 10: Often if the line itself is fine, look at previous lines. In this case you neglected to terminate the previous function prototype with a semicolon. The error wasn't detected until line 10, where it caused the compiler to puke.

Line 102: numemps is an array, but you compare it with an int. The two types are not compatible.

Line 115: i was never declared. Line 115 should look exactly like line 102. The error from line 102 won't occur because in this function, numemps is just an int and not an array.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Well, the error says that your query is wrong, so that's a good place to start. ;) My guess would be because Access is having trouble parsing "Tel number", and surrounding it with brackets would fix the problem:

string myQuery = "INSERT INTO Parent( Name, Surname, Address, Postcode, [Tel number], Email, UserName, Password) VALUES ( '" + TextBox1.Text + "' , '" + TextBox2.Text + "' , '" + TextBox3.Text + "' , '" + TextBox4.Text + "' , '" + TextBox5.Text + "' , '" + TextBox6.Text + "' , '" + TextBox7.Text + "' , '" + TextBox8.Text + "')";

This is assuming "Tel number" actually has embedded whitespace in the database schema. Otherwise it's a typo and you need to remove that space. I mention this as an alternative because UserName doesn't have a space, which suggests either an inconsistent schema definition or a typo in the C# code.

But typically when getting errors like this I'll trace the query or print out the end result that gets run, then copy/paste and run it directly from the database. Often it's easier to debug from there than simply going by the stack trace in C#.

pritaeas commented: Brackets... I should've known. +13
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

what is the best boook?

The one you have the easiest time understanding. All books will get you started. Some are better from an experts view, but may not be suitable for all beginners because everyone learns differently and understands different explanations of the same concept. It's actually more important that you get a book you can follow than getting the "best" book.

All of the ones you listed are good.

and what is the difference between C++ primer and c++ primer plus?

I think the question should be what's not different? And the answer would be that "C++ Primer" is in both names. Otherwise they're different books written by different authors. Both are suitable, of course, and cover the necessary material to learn C++.

why not the newer version(primer plus 6th edition?

That's a different book. The 5th edition is the most recent for "C++ Primer".

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Yup, it works now, with .clear() :). Thanks!

As a side note, the reason for that is the status flags of a file stream object are independent of the file that it points to. So if you open a file successfully, read it to EOF, then close it, attempting to open another file and read from it using the same stream object wouldn't work because the eofbit would still be set for the object.

As another example, your specific problem is that the open() member function failed on an invalid file name. This sets the failbit, which remains set even when you try to open a valid file name.

Calling the clear() member function clears the status bits.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

C style strings are pointers to characters

Add "sometimes" in there any I'll agree with you. The definition of a string in C is a contiguous sequence of zero or more characters terminated by '\0'. That means you can represent a string with an array (note that arrays are not pointers), or with a pointer to the first character in a block of memory that matches the definition.

The reason I mention this is because it causes a lot of confusion, and I think it's imporant in this case to be pedantic.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

It means print either doesn't exist entirely or doesn't have a definition. Presumably it's a function, which means you probably declared it but didn't define it.

totalwar235 commented: that was the answer +2
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

That's not a bad guess, but the assumption there is that SREC is its own type, so:

SREC grades[500];

No doubt you know how to declare simple integer variables:

int field;
int size;

Now the only problem is wrapping those three into a structure.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

i dont understand ur point......

My point is that something is wrong, you know what line it's on, and I can't look over your shoulder to properly hold your hand while debugging.

nd what is the reason behind that index is out of range

That's the question you're trying to answer by debugging the exception. You've rejected all of the possibilities I've pointed out, so now it's up to you to debug the line, add breakpoints, add watches, hover over shit, and look for values that aren't what you expected.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Admittedly with 951 down voted posts, it appears he/she is doing something wrong

Note that the vast majority of those votes were made by a single person. When looking at votes, also look at the unique voters. If the number of votes is high and the number of voters is low, that means a small number of accounts were used to make the votes.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

The virtual machine would have its own registers simulated to match the simulated platform. Nothing else would make sense given that the host could be running a number of virtual machines.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

That's by design. The button goes away to ensure that you don't click it again (and thus create a duplicate post) while the submit code is running.

Just be patient, it should finish in a few moments at most and then refresh to show your new post. Sometimes server load causes things to run more slowly than we'd like, but I haven't ever seen replies take more than about 5 seconds to finish.

If you're getting really long wait times, please let us know.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

@NP-complete, the word inclusive in pseudo code means you do not include the value in your range.

Actually, it's the other way around. Exclusive means that an end of a range is not included and inclusive means that an end of a range is included. The square bracket means inclusive and the paren means exclusive, so:

[a,b] - Fully inclusive, closed
(a,b) - Fully exclusive, open
[a,b) - Half open, excludes b
(a,b] - Half open, excludes a

Or in other terms, [a] represents the set {a} while (a) represents an empty set {}.

What I said means [1, array_size).

What you said means [1,array_size], which is congruent with the usual pseudocode interpretation. If what you meant was a half open range then it would be closer to:

for each index starting from 1 up to array size - 1

If it is exclusive, it means the value will be included in the range.

I find your explanation hilarous given that include and exclude are opposites. ;)

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

It works fine on my end. What numbers are you typing? What compiler and OS? As Nathan asked, what does "it just stops" mean?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

It's easy to perceive rudeness from someone who's trying to help, especially if they tend to cut through the bullshit and tell things like they are. If you think someone is really acting out, please report the post so that a moderator can deal with it. Creating a thread like this just comes off as childish and petty.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

sorry but i have no time. >.<

You probably had time, but dicked around to the point where you don't have time. That's entirely your fault and quite frankly, getting burned by procrastination is a fantastic way to learn the benefits of time management. I subscribe to the school of hard knocks, so I'll refrain from helping you on this. Maybe someone else will be more charitable.

Begginnerdev commented: Yep +6
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

By default std::sort() uses operator< to handle the relation between items. Since you have neither an overloaded operator< nor specify a custom comparison function, of course it doesn't work.

Consider using the three argument version of std::sort(). You can find details and examples here.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

unresolved external symbol "public:_thiscall TREE::TREE(void)" (?? 0TREE@@QAE@XZ) referenced in function_main

I don't see a definition for your default constructor, which your compiler seems to agree is missing. So I'll go out on a limb and say that you forgot to give it a body and need to do so to fix the error.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Finally, you might want to consider using std::copy as an alternative to memcpy, the syntax is nicer, there's some kind of type-safety in there and I don't think that there's any real efficiency difference between them. std::copy can actually be faster in some circumstance

I'd be shocked if std::copy() were more efficient when copying non-POD types because it guarantees that constructors are called and all the nifty stuff that makes C++ work happens. For built in and POD types the compiler will likely optimize to the point of being competitive with memcpy() if not equal to memcpy(), but I have trouble believing that it could ever be faster. memcpy() just blindly copies bytes, usually in the most efficient way possible for the platform. The definition of std::copy() isn't conducive for the optimizations that memcpy() is capable of.

What's really terrifying is that memcpy() on non-POD types:

  1. Doesn't call constructors.
  2. Doesn't respect the structure of class hierarchies.
  3. Is technically undefined behavior.

Therefore, use of memcpy() is considered a bug for all but built in and POD types. So you kind of ended up at the same suggestion I'd make, but for different reasons. ;)

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Start with spelling and grammar. All the technical knowledge in the world won't get you a job if your level of communication is only competitive with pubescent girls texting on their smart phones.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

So what I'm reading is that you want to get credit (in e-peen points) for solving your own problem, and possibly even deny credit to others because they failed to solve your problem?

p.s. Yes, I'm trolling you a bit with that second part. Yes, I'm a bit of an ass. ;)

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

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

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

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

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

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

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

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

You can undo it, no worries. ;)

pritaeas commented: Figured it out after posting. +0
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

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.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I don't really understand, why would the sorted array be advantageous?

Take a hash table, regardless of implementation, and print out all of the items in sorted order. You'll discover that it's not as simple as just traversing the table, and that's the first advanage that comes to mind for a sorted array, where it is as simple as just traversing the array.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Realistically, a sorted array would be advantageous if you want to get a sorted listing of items, or do a ranged search or anything except an exact match. If all you're doing is searching onesie twosie, the hash table is conceptually faster. In practice the array and a binary search may be faster due to caching though.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Does the following code make p as a null pointer

Yes. Static variables are zero initialized, which for pointers means the equivalent of NULL. You can verify that this is the case (other than reading the standard documentation) with a simple test:

#include <stdio.h>

static int *p;

int main(void)
{
    if (p == NULL)
        puts("It's NULL!");

    printf("Zero initialized address: %p\n", (void*)p);

    return 0;
}
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I don't why I am asking this maybe to gain your opionions... though I am not asking daniweb to change it's colors... but aside from DANIWEB being purple what other color should be it's theme color?

At one point several years ago each forum category had its own color, such as red or green. It wasn't memorable though; I honestly can't remember the color of the software development forums, and I spent far too much time on them...

As for what the main color should be if it weren't purple, maybe steel blue?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Anytime you get a large negative number, there are two things to check straight away:

  1. Any uninitialized variables in your math.
  2. Any out of bounds indexing or invalid pointers (they can corrupt other variables).

Either way the problem isn't in rand(), it's your code doing something funky.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

my question was why does it gets inialized during COMPILE time only?

The zero initialization is historically due to where static variables were stored in the executable image. They were typically placed in the BSS segment of the image, which typically included zero initialization of memory blocks. The C standard then blessed the semantics of zero initialization for statically linked objects, and we're where we are now.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

This article may help you with using the directional keys. Turbo C supports the getch() based solution. Note that it only describes how to capture and respond to those keys. What you do in the response is where most of the real work lies. ;)