deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I wonder if the underlying validation function got changed. I'll take a look when I get a chance.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I would think that DaniWeb has a basic set of operations that could be easily verified on the big 3 browsers.

I regularly do desktop regression tests using IE9/10, Chrome, Firefox, and Opera (latest versions due to obvious difficulties in testing back versions) on both Windows 7 and Windows 8. While I have seen the upload problem in Firefox once or twice since the current system went live, it's thus far proven too intermittent to effectively troubleshoot on my end. :(

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

If I ever feel strongly enough about a downvote to give a reason, I make sure to provide a comment and it becomes negative rep.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

ptr-p should return a address. But here its returning data ?

Subtracting two pointers returns the difference between the addresses, not another address.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I want to allow only numbers (int & float data type) input. How will I do that?

The usual and recommended approach is to simply allow the user to type anything and then throw errors if it doesn't match what you're expecting. For example with numbers only:

#include <ios>
#include <iostream>
#include <limits>

using namespace std;

int main()
{
    double num;

    while (true) {
        cout << "Enter a number: ";

        if (cin >> num) {
            break;
        }
        else {
            cout << "Invalid input. Please try again\n";

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

    cout << "The square of " << num << " is " << num * num << '\n';
}

This takes advantage of the fact that cin's operator>> will perform formatting and error checking on the input string based on the type of the target variable. In this case, operator>> will try to ensure that the input string is a valid floating-point value.

In cases where the default validation doesn't fit your needs, you would read the input as a free-form string and then validate it yourself. However, that's not typically recommended for basic cases as it can get complex quite quickly.

Finally, some people want to restrict input at the keyboard level. For example, completely disabling the non-digit keys when they're typed. This isn't supported by C++ natively, so you would need to write a non-portable input function that takes over the job of the command shell:

#include <cctype>
#include <iostream>
#include <string> …
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I know goto is not a good option but I think there is no harm in using it for small programs

The problem with goto is it's easy to get into the habit of using it as a crutch for not thinking about your code in a structured manner.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Actually that's not my code

It's not code at all, given that it's illegal C.

So, you mean there is not anyway to extract var as it is in my code?

I don't know what you mean by "extract". Can you be more specific, or use conventional terminology?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Arrays cannot be copied, but if you really want to do it with the assignment operator, you can wrap the array itself in a structure

#include<stdio.h>

typedef struct {
    int data[5];
} array;

void foo(array b)
{
    int i;

    for (i = 0; i < 5; i++) {
        printf("%d\n", b.data[i]);
    }
}

int main(void)
{
    array a = {1, 2, 3, 4, 5};

    foo(a);

    return 0;
}

Though the first question that pops up in reading your sample pseudocode is why do you need an array if it's an array of size 1? Why not just use a regular variable of the structure? Those are assignable.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

What's the exact error message?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

As a huge hint, here is a macro that calculates the number of leap years for a given year:

#define LEAP_COUNT(year) ((((year) - 1) / 4) - (((year) - 1) / 100) + (((year) - 1) / 400))
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

"the exe is not compatible...... make see whether you need 32 bit or 62 bit"

Are you paraphrasing, or is that the exact message? Also, how are you running the generated executable?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Agree -- scanf("%[^\n]%*c") is awkward and difficult to read.

It's also difficult to error check without using a dummy variable. A more robust solution with scanf() would actually finish with getchar():

if (scanf("%[^\n]", s) == 1) {
    if (getchar() != '\n') {
        // Error: expected a newline
    }
}
else {
    // Error: EOF or bad stream state 
}
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

We looked at a number of existing forum solutions and ultimately decided to write our own. Would you like to guess what a subset of existing solutions that were rejected might include? ;)

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Which version of vBulletin was it?

One of the later version 3 builds, I don't remember the exact version number. Due to the extreme amount of customization in place, we were unable to upgrade without significant effort.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

there is no need for dump and all..simply u get a string using %s..that's it

Okay, now type a first and last name. You introduced an error since the original code was retrieving a full line of input rather than a single word.

Ideally one would use fgets() for this purpose, but the original question was why the code was the way it was rather than how to make it better. And the answer is that the %[^\n]" scanset will read everything up to but not including the trailing newline character. So something else must be done to extract that newline character, hence a second call to scanf() that reads only a single character.

A sneaky way of doing the same thing would be:

scanf("%[^\n]%*c", stringName);

But all in all the best approach is fgets().

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Please do my homework for me

Barring an executive decision by Dani against it, I'd actually encourage deletion of obvious "do my work for me" threads, provided they don't have any replies. If they have replies, deleting the thread would be unfair to the people who replied.

Urgent help needed immediately

The joke about FAQ being the best title for top secret information is funny because it's so true. In this case, I'd say that as a moderator you should change the title to be more informative if possible, and dole out infractions for habitual uninformative titles.

No speak Engrish

Could you define "Engrish" for this thread? I see a lot of, for lack of a better term, Indian English where it's obvious that the person posting learned English in or around India. But it's still understandable, and if it's so garbled as to be intelligible or is clearly not English by any measure, that's against our rules and should be treated as such.

Insufficient Information

This one is tricky. I'd be thrilled if our rules added a clause about insufficient information when asking a question, but the likelihood of that happening is vanishingly small.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

You need to decide whether you want to use C-style strings or C++ std::string. If you want a C-style string, it's called like this:

int main()
{
    char s[] = "apples";
    char a = 'p';
    char b = 'd';

    cout << "Before swap of Char : " << s << endl;
    substitute(s, a, b);
    cout << "After swap of Char : " << s << endl;
}
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I have a code that when mouse hovers a button then it fires click event.

I would strongly recommend against this approach because it's unconventional and surprising. If an application I used did this, I would stop using it post-haste and look for an alternative.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

The tree being "mono" is already an invariant as far as nodes go, you'll never have two nodes with the same key. However, you can check for the tree being "mono" with a simple traversal and a test to see if any of the counts are greater than 1 (which may be what you mean by "mono"):

bool isMono(tnode *root)
{
    if (!root) {
        return true;
    }

    if (root->count > 1) {
        return false;
    }

    return isMono(root->left) && isMono(root->right);
}
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

You can pass a ref parameter in C++/CLI using the '%' operator, it corresponds to standard C++'s reference operator(&):

int MediaMogul::readlist(String^% name)
{
    name = "changed value";
    return 0;
}
n1csaf3 commented: Thankyou, I also worked out from that how to pass to the C++ DLL using item.readlist(ref name); in C# +0
ddanbe commented: Deep knowledge! +14
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

While I appreciate your willingness to share your knowledge, Daniweb's forum isn't a reference manual. If all you're going to do is post an extremely sub-par variant of MSDN, please stick to answering questions.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

WRONG : Console.WriteLine("%d * %d = %d",c,a,b);

Of course it's wrong, WriteLine() does not and never has purported to offer printf() style format specifiers. Saying that the above code is wrong is just like saying that the following line is wrong:

Console.WriteLine("FORMAT INT #1 LITERAL(*) INT #2 LITERAL(=) INT #3", c, a, b);

It's not even worth mentioning, because it's obvious to anyone who bothered to read a book or reference on C#. Of course, if your taget audience is the folks who learn by random guessing, then it might be helpful.

RIGHT AND PERFECT:: Console.WriteLine("{0} * {1} = {2}",c,a,b);

Actually, I'd wager that your right and perfect answer is actually incorrect. If it's not incorrect, it's misleading because the usual convention is for c to contain the result of a binary operation:

Console.WriteLine("{0} * {1} = {2}", a, b, c);
ddanbe commented: Well said. +0
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Our company previously had a major problem storing the binary files as blob in a relational db.

That's a bad idea in general. I'm not surprised you had issues. Usually you'll store references to the file (eg. a file system path or repository ticket) in the database to avoid the problems inherent in blobs. And if you were using blobs, you must already have something in place to access the data.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Theoretical or not, it's against Daniweb's rules.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Storage isn't an issue, and storing them as binary won't change the size unless the majority of the size is formatting of record data. The question you should be asking is "how do I need to access this data"?

For example, if you're just storing the files and will read them sequentially, the file system is adequate. If you need to search within the files and retrieve data based on complex queries, a relational database may be your best option.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

it is my opinion, may be i am wrong in this

As far as Daniweb's rules go, RJ wasn't even close to breaking the Keep It Pleasant rule. If the moderators or long time members don't call someone on their behavior, chances are that it's acceptable within the community.

atleast we must filter these words when anyone try to write these words.

We do filter such things (so if it's not filtered, it's OK), and also have rules in place to deal with excessively bad behavior. If you feel someone is being excessively rude, report the post and let a moderator deal with it. If it's not worth reporting, the problem is on your end. I think you're being too sensitive, which could very well be the overall problem that prompted this thread in the first place. Grow some thicker skin, dude.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Although possibly questionable ethically and technically, there is some mileage in the reasoning behind being the only one who understands your coding.

True, it's usually perceived as job security. However, I find that attitude so repulsive I'd be willing to fire an employee for it and give the new employee bonuses for the pain and suffering of figuring out or rewriting the obtuse code. A programmer that writes bad code as job security isn't the type I want to employ.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

how are they better at selling themselves ?

That's impossible to answer.

what does that exactly means ? :(

Google for "selling yourself". There are tons of resources, but ultimately it's about being likable and making yourself look like the person the interviewer wants.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

what the hell the problem is ?

They're better at selling themselves, and probably good at bullshitting too.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

it didn't get this line.. can you explain it ?

It was a somewhat joking way of saying that your expectations are too high, and there's no reason to be depressed about your results so far.

what to do ? :(

There's nothing you can do other than keep trying. Rejection is part and parcel of looking for a job. However, there's absolutely nothing wrong with reaching out to your contact at the company after a rejection and asking for advice on what you can do to improve your marketability.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

If one can write an algorithm that is significantly faster than a brute-force one, that is better.

Is it? What if the brute force algorithm was fast enough already? What if the faster algorithm is so godawful complicated that the original author barely understood it and left the company? One of the first things I try to teach college grads is cost benefit analysis for code. It may be cool, or theoretically superior, but if the cost exceeds the benefit, it's an inferior solution.

But all my peers and companies that recruit interns look for people who can write algorithms that are fast.

Obviously you shouldn't intentionally write slow code, but fast has a price, and if an employer doesn't understand that, they're not worth working for.

I just fail to see the wonderful patterns that arise out of the better(faster) algorithms.

Studying algorithm and data structure design would be a good start. Without a strong foundation in the theory, I'm not sure you'd suddenly start seeing those wonderful patterns just because you're under a time or resource crunch.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Define "better". Do you want to win contests or be a good programmer in general? Do you want to write professional quality code or code that just solves the problem as quickly as possible, and maintainability be damned?

That's the difference between competition and software development. Most of the time, code that should be in contests would miserably fail a code review. Likewise, good production code will general lose a contest consistently.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

i have got 3 rejections yet in directi (second-last round), AMZON(last round) and facebook (first round). how to make myself confident ?

Here's a bit of perspective: I wouldn't be surprised if Amazon or Facebook rejected me (and I'm not familiar with Directi). Since you seem to hold me in some regard, what does that say about your expectations? ;)

first of all: get realistic. 3 rejections are about equal to nothing. most sollicitants these days get dozens, or some even hundreds of rejections before actually finding a job, welcome to modern day economics, I'm afraid.

And that's with the folks who have experience. A newbie fresh out of school is a big risk, so you're more likely to get rejected.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Throw it out before it kills you.

BBCode was far worse, and throwing out both pretty much exhausts our options if we want to be consistent with what people know and understand.

What is more important?
1 You and your staff like it.
2 Members like it.

Of the two you stated, we chose #3: members are capable of using the formatting system without screwing it up 8 times out of 10. With BBCode we often spent more time fixing people's mistakes than fighting spam, and with the huge bullseye to spammers that vBulletin is, that's saying something.

Clicking on Log Out I ended up with:

What page were you on when you clicked the Log Out link?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I don't think that people are that blind or illiterate to not see or understand that a solved ie 5 year old thread, has a five years old solution!

Even with the big notification in the quick reply, we still see people posting to threads that are several years old as if they were started just yesterday. It's a short leap to imagine people voting with the same tunnel vision.

I'm not arguing for or against a time limit, just pointing out that this situation is far from improbable.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

That's because Daniweb is infinite.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

What about it?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Order of operations, my friend. (int*)a + 1 converts a to a pointer to int, then increments it as a pointer to int. What you wanted, according to your expected output, was to increment a first, then convert to a pointer to int:

static int *p[] = {(int*)a, (int*)(a + 1), (int*)(a + 2)};

Notice the parentheses around a + 1 and a + 2.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Check your errors. For example, whenever opening a file fopen() returns NULL on failure:

FILE *f=fopen(file,"w");

if (f == NULL) {
    perror("Error opening output file");

    /* Whatever exit or recovery strategy you choose here */
    exit(EXIT_FAILURE);
}

If nothing else you may get more useful information in the way of first knowing that fopen() failed and also what the exact error was.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

How can I do that?

You could actually read this thread instead of guessing at what people are saying. I posted how to do it with std::string.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

because u asked some bad things to him otheriwse all 4 rounds response ws awesome for you.

Your summary of the situation puts the interviewer in a negative light. I'd suspect that while your technical skills were good, they didn't feel you were a good fit for the environment due to your questions. There's not much you can do about that; if you got the job then there may be a higher chance you'd be unhappy with it.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

How can I do it with sprintf()? Before I posted here, I scoured the internet all over, and all the explanations for sprintf were to complicated. I couldn't understand.

If AD's example above was too complicated, I'm not sure what to tell you, because that's as simple as it gets. For your specific needs:

double n = 1.23456;
char s[10];

sprintf(s, "%.2f", n);

In C++ there are many more options, but I suspect those will confuse you as well. The usual solution involves stringstreams:

double n = 1.23456;
ostringstream oss;

oss.precision(2);
oss << fixed << n;

string s = oss.str();
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

My guess is that you shouldn't use delete to deallocate the string's memory which was allocated with strdup (which is not a standard function, btw).

Good catch, I totally brain farted on that one. ;)

why did you use const?

Why not? Defaulting to const is safer, and in this case there's no reason to have write access to the object being copied.

what's up with the double reference?

That's an rvalue reference from C++11.

How are they enabled using "= delete" ?

I don't understand the question. Using the C++11 =delete syntax tells the compiler not to provide implicit implementations of the member function. In the case of a copy constructor, if you don't write one explicitly, one is provided for you with a shallow copy. Since you don't want a shallow copy, the two options are to write a copy constructor or disable copy construction.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

The indexing works the same way since it's nothing more than an array of 2D arrays. If you add another dimension of 2, duplicate what you posted each with an index of 0 and 1: 000 001 010 011 100 101 110 111.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

i was solving a problem which didn't have specification to create them

If it's a school assignment then you don't need to go out of your way, just be aware of the issues. In real code, I'd prefer in most cases where shallow copy is a problem to either implement all of those member functions, or implement a subset of them and disable the rest. For example if you didn't want your class to be copyable, movable, or assignable:

class CObject
{
    char *mName;
public:
    CObject(char *name) : mName(strdup(name)) {}
    CObject(const CObject& rhs) = delete;
    CObject(CObject&& rhs) = delete;
    ~CObject() { delete[] mName; }

    CObject& operator=(const CObject& rhs) = delete;
    CObject& operator=(CObject&& rhs) = delete;

    const char *Name() const { return mName; }
};

The workaround to such behavior prior to C++11 was to make the member functions in question private:

class CObject
{
    char *mName;
public:
    CObject(char *name) : mName(strdup(name)) {}
    ~CObject() { delete[] mName; }

    const char *Name() const { return mName; }
private:
    // Noncopyable. Move semantics were added with C++11, so not necessary to deal with here
    CObject(const CObject& rhs) {}
    CObject& operator=(const CObject& rhs) {}
};
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I tried this, but i get debug assertion failed. From what i've read, it's because my object are destructed for a multiple number of times.

If you're calling the destructor multiple times, something is very wrong with how you're using the class. Perhaps you're trying to delete the object pointer twice?

std::string is STL? because we are not allowed to use it.

Technically std::string isn't a part of the STL, but it is part of the extensive standard library of which the STL is a subset. If you aren't allowed to use "the STL", std::string is very likely to be implied in that restriction.

@deceptikon, why do i have to implement a copy constructor and to overload the assignement operator when creating a destructor?

Because if you use the default copy constructor and assignment operator, you'll have two objects that refer to the same block of memory. This is a very risky situation that would end up in trying to delete the pointer multiple times (on the destructor call of each object).

This is the rule of 3 (and more recently the rule of 5) intended to handle the management of resources owned by a class as safely and completely as possible.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

why is mName char* instead of std::string?

From previous threads, I can safely conclude that the OP isn't allowed to use such convenient classes yet.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Huh? How could a downvote become invalid due to changes in technology?

The answer may have been excellent 10 years ago, but as technology and techniques change it becomes outdated and bad advice. If posts aren't read in the context of their post date, I can easily see downvotes showing up on long dead threads.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

There are actually a number of problems with that function, though returning a pointer to a local variable is probably what the interviewer wanted.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Also keep in mind that if you need a destructor, you probably also need a copy constructor and copy assignment operator (and possibly a move constructor and move assignment operator for C++11). I'd also avoid a protected data member in favor of a private data member and public const getter. That way CObject absolutely controls mName, and can make assumptions about its integrity (ie. assuming that it's always safe to delete the pointer). For example:

class CObject
{
    char *mName;
public:
    CObject(char *name) : mName(strdup(name)) {}
    CObject(const CObject& rhs) : mName(strdup(rhs.mName)) {}
    CObject(CObject&& rhs) : mName(rhs.mName) { rhs.mName = nullptr;  }
    ~CObject() { delete[] mName; }

    CObject& operator=(const CObject& rhs)
    {
        if (&rhs != this)
        {
            mName = strdup(rhs.mName);
        }
    }

    CObject& operator=(CObject&& rhs)
    {
        mName = rhs.mName;
        rhs.mName = nullptr;
    }

    const char *Name() const { return mName; }
};