deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Thanks! problem solved!

I expect that you'll be back in relatively short order with the same error and a different cause? Not that I'm attacking Gonbe for pointing out the problem this time, but you still need to learn how to trace access violations.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Ignore the above it would be an answer so it's evil and totally stupid of me to post.

No offense, but this statement makes you seem childish and bitter. Surely you can tell the difference between explaining how const works and posting a complete working program for an obvious homework question, right?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

i need codes for the program

Daniweb is not a homework service. You do the work, and we help you with specific questions and direct you toward how to fix things when you get stuck. Last I checked, "help" doesn't mean "do it for you".

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

So we still know the fundamentals but nothing too advanced for decent oops.

The humorous thing is that in a few years you'll probably see "decent OOP" as unmaintainable shit and revert back to the fundamentals. The process of learning, especially with C++, seems to revolve around overcompensation. You learn a new feature and abuse it until it seems like a bad feature, then overcompensate by cutting out any use of the feature.

Eventually, the better programmers take an attitude of moderation with a strong tendency toward simplicity. So I imagine what you're calling "decent OOP" is something that experienced programmers will be using with moderation.

-is it a decent project proposal?

Yes. I'd recommend the store option, or more specifically a point of sale system, but interface details are largely irrelevant at this point.

-what is a databse basically providing?

Any persisted data. For a hospital it would be medical records like personal information, medical history, visit history, and procedure details.

-Should it be predefined (already names and histories and the patient's health notes are fed into it or are to be input)

It doesn't matter, though some seeded data would be a good idea for development purposes.

-how big the databse should be?

As big as it needs to be? :P I suspect you'll just be using a simple file for the database, and the size of the file is largely irrelevant given that this isn't a database …

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

hmm tats wat iam asking a proper link for it

Pardon my confusion, but is it really too difficult to reason about with nothing more than an understanding of linked lists and a functioning brain? You're going to encounter situations where there's not a web page to teach you everything about a subject, and your only recourse is to figure it out through experimentation.

Now, I could certainly do a google search for you and post some links here, but I think it might be better to force you to be inventive while things are still relatively easy. If you don't have practice in real problem solving (and not just regurgitating what you've read in a book or on a website), you'll be massively overwhelmed when the tasks become truly complex.

WaltP commented: But if I google it, how will I know which link will be understandable??? 8-P +14
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

The most basic solution is to wrap the code in pre tags to preserve the formatting. But be careful with C++, because you'll need to remember to escape certain characters like angle brackets and the & operators, otherwise they'll be stripped when the browser can't interpret them as HTML. It's annoying looking at naively posted code and seeing #include with the actual header missing. ;)

You could also wrap the code in HTML code tags. I'm not sure off the top of my head if that will fix the stripping problem or not though, it's something to test.

If you need highlighting as well then there are a number of syntax highlighting options out there such as Google Code Prettify or SyntaxHighlighter.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

thats a neat way to print ;) gonna do that myself when possible :)

Don't do it because it's neat. Do it when it makes the code easier to read.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Arrays cannot be compared with the == operator. You really have no choice but to loop over the elements and compare them onesie twosie:

int equal = 1; /* Equal until proven otherwise */
int i;

for (i = 0; i < 5; ++i) {
    if (output_1[i] != output_2[i]) {
        equal = 0;
        break; /* No need to continue the comparison */
    }
}

if (equal)
    puts("are equal");
else
    puts("not equal");

This is assuming the arrays are of equal length, of course.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

can you please write how to do it using intrptr_t?

Don't get confused with stuff like intptr_t. All you're doing is casting the value stored by a pointer (not the value stored by the pointed to object) into an integer type so that bitwise operators can be used on it.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Honestly, if I were you I would be more worried about your atrocious spelling and grammar than employers giving two shits about any cheating scandals when you were in school.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

will this work?? i think it should work as long as bigDaddy is big enough :D

You have the basic idea, though don't forget to populate bigDaddy with the first partial line or the full line if buf is big enough:

char buf[BUFSIZ];

bigDaddy[0] = '\0'; /* Empty bigDaddy for strcat */

while (fgets(buf, sizeof buf, stdin)) {
    strcat(bigDaddy, buf); /* Always append the buffer */

    if (buf[strlen(buf) - 1] == '\n')
        break; /* Only break when a full line is read */
}

As AD mentioned, if bigDaddy is already big enough then just read directly into it. The partial line stuff with fgets() is mostly for when you're building a string dynamically and don't know how long the line might be (or similar situations).

getline() is a c++ function not useful in C programs.

A fact which is totally irrelevant to this thread because the getline() function being discussed is a C function provided by GCC. See the link in the first thread that says "read here"? It would be a good idea to read there before making assumptions. ;)

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

When you do this:

sqrt(123);

It's functionally identical to this:

double temp = 123;
sqrt(temp);

The integer value is assigned to a double parameter, which is perfectly legal as I described above.

I don't have my hardcopy of K&R handy right now, so I can't fact check what it says, but the cast isn't required, and sqrt() is well behaved when given integer values. In C++ you'll get ambiguity errors due to overloading of sqrt(), but in C it's all good.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

doesn't sqrt() take argument of type "double" by default??

No, it takes an argument of type double absolutely.

the book says sqrt() will return non sensical values if given argument of type int?

Which book is "the book"? If you pass an int to sqrt(), it will be promoted to double. The two types are compatible because double can exactly represent any value in the range of int. In this case I'd say either your book is simply wrong, or you're misinterpreting what it says.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

fgets() is bad only if you don't understand how it works. I'd wager that the label of "unreliable" in the page you linked to has to do with how fgets() handles partial lines. If the line in the stream is longer than the buffer provided to fgets() can hold, no newline is stored at the end. This way the programmer can check for a newline and make another call to get the rest of the line (or the next partial line)

This is correct in the presence of extra long lines:

char buf[BUFSIZ];

while (fgets(buf, sizeof buf, stdin)) {
    fputs(buf, stdout);

    /* Did we read a partial line? */
    if (buf[strlen(buf) - 1] == '\n')
        break; /* No, all done */
}

also i think the default getline() isnt in C , is it??

getline() isn't a standard function, it's a library extension under GCC. Therefore, getline() is also bad because it's not guaranteed to be supported. ;)

whats a '**'? why is it used??

It's a pointer to a pointer. The reason that getline() here uses it is because the pointer you pass may be reset to point to memory allocated within getline(). It's really just the same reason why you'd pass a pointer to an int if you want to modify the value of the int in a function:

void foo(int *p)
{
    *p = 123;
}

int main(void)
{
    int x = 0;

    foo(&x);
    printf("%d\n", x); /* Prints 123 */ …
somjit{} commented: this is going to help a looot of people..! +2
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Hmm, does this mean that Walt is the new Narue? Before it was always Narue's sharp tongue that everyone feared. ;)

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

oops! first time you got angry! :(

Often a curt reply can be extremely effective.

If you manage to actually make me angry, much less angry enough to post without deep consideration behind my words, you'll be in a very small and elite group that I won't need more than two hands to count and will remember forever. In other words, ain't gonna happen. ;)

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Your push() member function is broken. In the case where top isn't NULL, you have three lines:

top -> next = temp;
top = temp;
top -> next = NULL;

The first thing to notice is that top->next is always reset to NULL, always. That line is a bug and should be removed. You're also pushing in the wrong direction. The top of the stack is the most recently pushed item, so you need to set temp->next to top rather than top->next to temp:

temp -> next = top;
top = temp;

The display member function also has an off by one error wherein you don't print the oldest node in the stack. Your condition should check temp against NULL rather than temp->next:

while(temp != NULL)
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

ItemList list();

This doesn't do what you think it does. Due to a parsing ambiguity, the resolution of the above declares a function called list that takes no arguments and returns an object of type ItemList. It doesn't create a new object called list with a type of ItemList, to do that you need to remove the parens:

ItemList list; // Create a new ItemList called list

Confused yet? ;)

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Why don't you try using FireFox. Its fast and sleek.

Patient: "Doctor, it hurts when I blink."
Doctor: "Don't blink."

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

so when i say that range is fix like the INT_MAX, then can't i say that it is O(n) ?

How many languages would you like me to say "no" in before I make my point?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I think you misunderstood him -- he meant to say "in my opinion"

I understood perfectly. It was a joke, as evidenced by the smiley at the end.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

If you still do not understand the voting system then I fear we will have to break out the picture book version of the explanation :)

See Spot. See Spot vote. Vote Spot, vote! :D

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

This is the syntax for the configuration files of Apache servers. This kind of syntax is used inside httpd.conf, apache2.conf, .htaccess and the files used to configure virtual hosts.

We don't have a highlight mode for that, it's probably interpreting it as XML. But I absolutely agree that producing different highlighted text than raw text is a bad thing, and when I get a chance I'll see if it's something that can be fixed without herculean efforts.

cereal commented: many thanks! +0
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

What is the OP's question ?

The OP's question was clearly "d". Can't you read? ;) Now we need to figure out what the question means and answer it. :rolleyes:

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

this just takes in one value, so i cant enter double digit numbers here!

I assumed that's what you intended. If you want to handle multiple digits then you're getting into the conversion stuff that scanf() does. It's not especially difficult for integer types (floating point types are a pain in the booty), but there are niggling edge cases that need to be considered for a truly robust conversion.

However, the core of the algorithm is this:

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

    /* Positive numbers only! */
    while (*s && isdigit(*s)) {
        result = 10 * result + (*s - '0');
        ++s;
    }

    return result;
}

You progressively get a digit, find it's numeric value (by subtracting the character '0', see if you can figure out why this works), add that value to the result, then multiply or shift the result left by a tens place to make room for the next digit. For the string "123", the trace would look like this:

10 * 0 + ('1' - '0')  // result == 1
10 * 1 + ('2' - '0')  // result == 12
10 * 12 + ('3' - '0') // result == 123
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

i dont get any output for case1 (ie char2shrt()) and case2 (ie int2shrt()).. any ideas on that?

'h' is a modifier to the %d specifier, you need them both: "%hd"

i do get an output for case 3 (ie shrt2int()), but have to work out in binary if its correct or not.

You don't need to fiddle with binary to determine correctness, just look at an ASCII table. Type a character and check the corresponding value in the table to verify. For example, if you type 'a' the result should be 97.

*type* input[40] means what?

It means input is an array of 40 objects of size "type". If "type" is char then you have an array of 40 bytes, if "type" is int then you have an array of 40 integers where each one is 4 bytes (going with your assumption). The size of an array of 40 will always be sizeof(type) * 40. Note that sizeof(char) is always 1, and char corresponds to the system's byte size, so an array of 40 char is equivalent to 40 bytes.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

FYI: Dani and I typically use Area 51 for testing stuff in production so as to avoid cluttering the publicly viewable forums with such things.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Can you try clearing your browser cache (not your cookies) and try again? :)

Same behavior.

Dani commented: Testing :) +0
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

It might be just you, I haven't seen that issue at all. At least not with Chrome, what browser are you using to test with?

nitin1 commented: i always comment on posts like this one (Y) ;) +0
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

how fgets() is more better than what npcpmplete has said.

It more clearly shows your intention (read a line of string data), avoids the overhead of scanf() because fgets() doesn't need to interpret a format string, and of course it's easier to miss the huge bug of not including a field width with scanf(). Another consideration is if the size of the array that will hold the string isn't a compile time entity, in which case you need to construct the format string at runtime in a very awkward manner:

char *buf;        /* Buffer with unknown compile time size */
size_t size;      /* Runtime size of buf */
char fmt[BUFSIZ];

sprintf(fmt, "%%%d[^\n]%%*c", size);

/* Now use scanf() after constructing a format string */
if (scanf(fmt, buf) != 1) {
    /* Handle an input error */
}

There's nothing really wrong with using scanf(), assuming you use it correctly, but it's kind of like using a wrench as a hammer. It works, but it's not the most obvious tool, and the more obvious tool will probably work better.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

First you have this:

#define radius

Then this:

cout<<"\nRadius is " << radius << set(8)<< "PI is" <<PI;

What exactly were you expecting to get printed when radius is replaced with nothing? The end result after preprocessing is this:

cout<<"\nRadius is " << << set(8)<< "PI is" <<PI;

And that's obviously a syntax error. You have the same problem anywhere radius is used to mean anything except nothing.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

i want to gain full knowlege of programming language..

Um...programming isn't that simple. Not even the creator of a programming language has "full" knowledge of it, because "full" knowledge encompases more than just the trivia of syntax and semantics. Even if you're a book smart pedant who can quote chapter and verse of the language definition, that doesn't guarantee that you're even remotely proficient with using the language.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

What's up with that?

Obviously Daniweb is so awesome that Microsoft decided to emulate us. :)

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Not fair, deceptikon -- giving me rep and taking it back! Positive rep, even as a test, is a good thing! :P ;)

The test was actually to see if you'd get negative rep. Aren't you glad the effect was as I hoped? ;)

On a serious note, I hope you aren't planning on changing the wayt the box and arrows interract. I happen to like the way they work now.

I'd like to make it more clear visually which arrow the box is affecting, not change the behavior.

Oh, and the comment you made was left in my list of rep even after you removed it. That might be a bug...

Yeah, I'll need to look at that. If it's practical to do so, the summary should match what you would see by browsing the posts.

WaltP commented: Thanx ;o} +0
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

This thread was marked as solved. Did you solve your own problem?

On a side note, is it really so hard to type "input"? I mean, it's got to be less awkward to type and is only two keystrokes longer.

nitin1 commented: will not do this type of mistake in future +2
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

but what to do ? Nobody was replying and i was eager to get a reply.

My first instinct is to say don't put all your eggs in one basket. It's unreasonable to expect that Daniweb will have all of your answers, so while waiting for a reply you should be doing as much research as possible in an attempt to answer your own question.

i just need to ask how can i save the string in C ?

It looks to me like you were asking how to write a suffix array based sort, which isn't exactly trivial. Might I suggest looking at existing programs that do what you want? I have no doubt you can find at least one on google.

nitin1 commented: quite well answered! +0
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

atleasy one must reply.

Why? Replying to threads is strictly voluntary. Just because you really want an answer doesn't obligate anyone to provide one.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

If you have two non-black spots going in different directions from a cell, then that's an intersection:

bool is_intersection(char board[M][N], int x, int y)
{
    if (board[x][y] == '#')
        return false;

    return
        (board[x - 1][y] != '#' || board[x + 1][y] != '#') &&
        (board[x][y - 1] != '#' || board[x][y + 1] != '#');
}
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

if (c == ' ' || c == '\n' || c = '\t')

One of these things is not like the other. Look very closely, I'm sure the book didn't mix up operators.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I respect the OP for coming back with an improved attempt, and in keeping with the spirit of DaniWeb, I'd be more than happy to offer further support with it.

I'm also happy to help, but the OP has failed to ask any kind of specific question about how to improve the code. Both threads strike me more as "look at my awesome code!" rather than "I'm concerned with these parts of my code, how can I improve it and do you have any other suggestions?"

I'll also note that my first suggestion was immediately rejected as "completely unnecessary". That's not exactly indicative of an open mind.

Respectfully, I don't think that's called for.

Respectfully, I do. I get the distinct impression that the OP is getting a big head, and that big head needs to be deflated otherwise his progress will quickly stagnate. The more you blow sunshine up someone's ass, the more they'll have unreasonable expectations.

WaltP commented: Testing where rep counts. +14
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

The only reason I have used words like "jaar", "maand" and "dag", is because it was easier for me to remember and easier to program. For example: using the the word "socialism" for the current year would be a little bit confusing.

I don't think you understand. Unless the reader knows what jaar, maand, and dag mean, they'll have trouble understanding your code without making assumptions based on context or doing a Dutch to English translation. I'm suggesting that you use the English version of the same words: year, month, and day. I'm not suggesting that you name your variables something completely random, and I can't imagine how you inferred that.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

So we traded the below par VBulletin for the below par parser?

For one thing, that's a nonsensical comparison given that vBulletin composed the entirety of Daniweb while the current editor is a relatively small (yet important) piece.

For another thing, bwahahaha! No, the utter shittitude of vBulletin's entire source base is insanity compared to CodeMirror's parser. It's actually a miracle that Dani was able to customize even a fraction of what she did under vBulletin. We're so much better off now.

And note that I said "awkward", not "below par". It's a perfectly good parser, but there are quirks that make lookahead and lookbehind tricky. I may not need to do anything clever to support a spell checker, but with my luck that's being unreasonably optimistic. ;)

I assume a slickly designed parser will be coming eventually.

Nope, we're reasonably happy with CodeMirror now that the basic functionality has been nailed down. There was a point where code highlighting was buggy, but I think I've fixed that. Highlighting was the single biggest reason why we went with CodeMirror over other options.

I too would prefer a straight textarea, to be honest, but it's not hard to see the added value of an editor that has the feel of a native desktop application rather than an HTML form.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

@deceptikon then why don't we have this spell check yet ?

Because it's not as easy as flipping a switch, otherwise we'd already have it. I could add general spell checking without too much difficulty, but it would spell check everything in code tags too. That would be super fugly given that code is assured to have many many misspelled words, so I need to figure out a way to spell check words that aren't in either code blocks or inline code without complicating the whole world.

Keep in mind that I'm working within the constraints of a very awkwardly designed parser for the editor, as well as multiple third party libraries around highlighting and formatting that need to be kept in sync. I don't doubt that it can be done, I just need to find the time to focus on it.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

hm... tried that combonation and it didn't work.

And how are you testing for a correct answer?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I think we just need to convey our message.

Poor spelling can obscure the message.

here, many people are there who are not so good in english and don't spell correctly.

Actually, I've found poor grammar to be more obtrusive than all but the most grievous of spelling errors.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

You're storing passwords in the clear? That's really not a good thing. :P

A better system is to store at least a non-reversible hash of the password. Then when the user forgets their password, give them a temporary link to a reset form.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

deceptikon the question you asked are generally not asked in any job interview question, i have seen till date. i have solved around 1500 problems on various websites but i never come across such questions which you asked. google/ microsoft even facebook never asked this type of question.

That's intentional. All of the usual interview questions I've seen are stupid and tell the interviewer very little about a candidate's suitability for the position. What better questions to ask than dumbed down and abbreviated versions of what they'll encounter on the job?

I couldn't care less if you come up with a clever way to design a spice rack for a disabled person, or if you can figure out how to get a wolf, a lamb, and a sack of grain across a river. These things may tell me how you think, assuming you didn't look up the answers online before the interview, but they don't tell me jack about how you'd react to real problems or how well you'd fit into my team.

Though I do agree that the fizzbuzz program is a good way to weed out retards, and I'll use it occasionally as a first question. Others are simple but subtle algorithms like a binary search, or a safe copy in the presence of overlapping memory. These can promote conversation.

p.s i am talking about questions which company aksks to a student who has just completed his graduation like me.(after b.tech or bba or something …

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Geeks' Lounge and Community Center would probably be the best place, though if it's directed at C interviews the the C forum is also appropriate. And I don't care who starts the thread (you or myk45), just coordinate so that you don't both make one. ;)

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

but what to do in a situation when we don't know the answer fully correctly.

Say what you know and admit that you're not sure. You'd be shocked at how few people seem capable of saying "I don't know". In fact, it's so ridicuous that merely admitting you don't know the answer and suggesting ways to find it can land you a job all by itself.

np complete commented: nice +4