deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Acting as an intrviewer from any company ? it's a great job!

It's not really that big of a deal.

i afraid from them like they will eat me if i say something wrong ;)

While some nervousness is understandable and overly confident people raise red flags in an interview, being afraid of the interviewer is a bad thing. In my first programming interview (as the candidate) I wouldn't back down when the interviewer thought my answer to a question had a bug and I knew it didn't. I got that job over other, probably better, candidates because I was willing to fight when it mattered. Backing down and changing code to fix an imaginary bug very often introduces real bugs, and that can end up being a very costly mistake.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Have you ever gone as a interviwer to any university or college ?

No, but I regularly interview candidate programmers looking for a job in the real world.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

i mean it is not a well defined answer if a high-grade person(interviewer/teacher/professor) asks and i counter question him/her like this.

I'd accept that answer as an interviewer. It clearly and eloquently (in my opinion) shows that you understand the issues involved.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

if anyone asks me why sizeof is an operator not a function, then what exactly (very specific) i should say him/her

I'd ask a socratic counter question: how would a function (an inherently runtime entity) execute at compile time?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Type information is lost after compilation, that's why C decompilers suck ass. We've discussed this.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I don't understand the "question". Please elaborate.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

why it doesn't hold for C++?

I'd suspect that the person who wrote that was thinking of C++'s RTTI (runtime type information) features. That really has nothing to do with the sizeof operator though.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

but I'm nub sooo, what is compiler flag?

It's an option added to the command line invokation of the compiler. Right now you're probably only using something like this:

$ g++ myprogram.cpp

But you can add a huge number of options in the form of flags. For example, to only compile the code and not link it into an executable you'd use the -c option:

$ g++ -c myprogram.cpp

And then to link it into an executable separately from the result of the previous invokation, this:

$ g++ myprogram.o

Compiler options will take the form of either -<option> or --<option>, and you can find a complete list of them here.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

by the way, The code works for Turbo C, it doesn't work for gcc.

Which should be your first hint that the code is wrong. If it were right, all compilers would produce the same result.

I think the answer to the question is that scanf is not able to allocate memory for the input string properly

That's indirectly correct. The actual problem is that you were making assumptions about what scanf() is supposed to do, and failed to read the documentation to verify your assumptions. The fact that scanf() is indeed unable to properly allocate memory for the string is an irrelevant point because it's not intended to do so.

so it is having problem in assigning base address of the allocated string to the character pointer.

No allocation happens. scanf() writes to the address stored in the pointer you pass, and it's your job to make sure that the pointer points to enough memory to hold whatever length string scanf() might write to it. You passed an uninitialized pointer, and scanf() rightfully puked when it turned out that the garbage address stored by that pointer didn't refer to memory that your process properly owned.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Arrays are an aggregate type, you can't simply use the assignment operator. Copying is performed with the strcpy() function. argv[1] is also a string, so *argv[1] evaluates to a single character. I suspect you meant this:

strcpy(target, argv[1]);
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

in the 21st century, it is a world of multitasking dude!

When I divide my attention between projects, the quality of my work decreases exponentially. Just FYI, even in a world of multitasking, focus is important.

nitin1 commented: awesome statemtn ;) +0
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

my interst is C only.

If you only care about C right now then I'd suggest reading the standard and attempting to implement parts of the standard library. On top of learning how to properly use the library by writing it, you'll also learn a lot about computer science in the process.

nitin1 commented: hesitated my mind.. thinking to start with ;) +0
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

but why don't you buy a system rather than building it own your own ?

Because pre-built systems are never perfectly tailored to my needs, and often use cheap parts.

secondly, what exactly do you mean from scratch ? ;-)

From nothing.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

A good trick for avoiding this type of mistake is taking the size of the destination pointer rather than hardcoding the type:

int **m = malloc(5 * sizeof *m);
...
m[i] = malloc(5 * sizeof *m[i]);

This works because sizeof doesn't actually perform the dereference, it just evaluates to the size of the result as if had it been performed.

nitin1 commented: awesome trick i must say ;) +2
np complete commented: cool :) +3
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

@deceptikon i didn't get what yu trying to say. will you please re-write it in some other form ?

No offense, but I couldn't care less if you understand my post because it wasn't intended for you, it was intended for Garrett85.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

what exactly hhx is doing ? i have listend and used hx only and x. but what is hhx in the above code ?

hh is a new length specifier beginning with C99. It means that the object is the size of a signed or unsigned char being used as a small integer rather than a character.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

So according to you, it it will not work because it is not defined ?

It won't work if it's not defined. It if is defined then it'll work fine because that's the use case for extern.

secondly, isn't this an error as i am saying to compiler that x is defined else where and again i am defining another x, so isn't it a re defintion of x error ?

I fail to see what's so complicated about this.

  • You may have one definition, period.
  • You may have many declarations.
  • Code will not compile without declarations.
  • Code will not link without definitions.

That's all, don't overthink it.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

So is there any reason to use Windows Forms over WPF ?

Backward compatibility comes to mind. WPF was only added in .NET 3.0, and many of us still maintain "legacy" .NET applications (I still have a few targeting 1.1) or specifically target 2.0 for maximum portability.

Lack of desire to learn yet another API also makes sense. Microsoft has ADD when it comes to their GUI libraries. Once we learned Win32 they gave us MFC. Once we learned MFC they gave us .NET. When we got comfortable with Win Forms, they rolled out WPF. Every time the new API was the wave of the future and "you'll be using this from now on". I bet once we're comfortable with WPF they'll change their mind again and roll out something completely different.

Reverend Jim commented: Couldn't agree more. +11
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

These days all implementations ought to be compatible with the C standard.

That's where it gets tricky. There are four versions of the C standard at present:

  1. C90: The first official standard from ISO in 1990. All relatively modern compilers claiming to be C compilers should (and will likely) conform to this one.
  2. C95: C95 isn't really a full revision, it's C90 with normative addendum 1 from 1995. All modern compilers should (and will likely) include normative addendum 1 and thus support C95.
  3. C99: The second revision of the standard in 1999. Most compilers will not support this standard, or will only support it piecemeal.
  4. C11: The most recent standard from late 2011. C99 compilers are quickly moving to support C11, if they don't already, but non-C99 compilers aren't likely to in the near future.

If you're writing portable code, it's probably best to assume at most C95. Or you can take the perspective of "if it's standard, it's portable", and let consumers of the code find a conforming compiler.

And on a side note, Turbo C doesn't fully support even C90. ;)

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

But at least it's widely documented and doesn't have a horrible naming convention.

We may disagree a bit on what constitutes a horrible naming convention. ;) I won't try to defend the conventions from POSIX, but Win32 names are either excessively verbose or annoyingly hungarian.

I've never seen Dirent.h or any of those includes before.

They've been around for decades. I take it you've worked primarily with Windows systems and only recently moved to Linux? There's going to be a learning curve because even though the basic concepts are similar, the concrete details are different between operating systems.

triumphost commented: +1 I just moved to linux yes. I <3 Hungarian & CamelCase conventions lol. +6
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I'd say start by getting a simple barcode font, such as IDAutomation's free 3 of 9 font and creating some images. The 3 of 9 symbology is dead simple to encode and decode (it's really just a string with asterisk delimiters), which makes it a good symbology to get your feet wet. The hardware readers are also cheap, and there are free software libraries for reading 1D barcodes.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

If you want to increase the element that you find you would use the post increment operator not the pre increment operator.

The prefix operator is a better practice when the result of the expression doesn't matter. The reason for this is because conceptually prefix increment and decrement are faster due to no need for a temporary. Prefix increment works conceptually like this (not valid C++):

int& operator++()
{
    value = value + 1;
    return value;
}

While postfix increment works conceptually like this (still not valid C++):

int operator++(int)
{
    int temp = value;
    value = value + 1;
    return temp;
}

If you need the result then the difference matters because it's the difference between evaluating to the unincremented value versus the incremented value. But for statements like ++value; versus value++;, the result is ignored. Therefore it's best to use the version that has potential to be faster: ++value;.

For built in types it's largely a moot point because even the first C compiler optimized away the conceptual temporary. I think even Miracle C (the canonical "bad" compiler) performs this optimization. However, C++ introduces user-defined types, where the temporary may not be optimized away. You'll notice that people will recommend prefix increment or decrement for iterators rather than postfix, and this is the reason why.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

For updating the ProgressBar

That makes sense, though an equally viable perspective is that each file is a transaction and the progress bar tells you how many transactions out of the total have completed rather than taking granularity into how progress of each transaction. You don't really care about partial files, after all, only complete files. If a file is partially complete then that's an error condition.

My concern here is that manually copying a file introduces risk of corruption that File.Copy() will be more likely to respond to correctly.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

While one says "definition occures once through the program( memory is allocated once ), but the declaration can occur many times.", the other says "This means that the declaration is only one throughout the program but definitions can be many."

The first one is sufficiently accurate and the second one is completely wrong. I suspect the second one was written by someone who doesn't really understand the terminology and is using the wrong terms for the concept they're trying to explain.

Walt's explanation is reasonable, but a somewhat simplified version of how C handles object declarations and definitions. I'd recommend going with two guidelines that remove the special cases and leave you with a very simple result:

  1. All declarations are qualified with the extern keyword and have no initializer.
  2. All definitions include an initializer.

With these guidelines, int x; is no longer an option. It can either be a declaration:

extern int x;

Or a definition:

int x = 10;

Now there's no ambiguity and the two are easy to identify.

x = 10;, of course, is an assignment and completely unrelated to declarations and definitions excepting the assumption that by naming the object there's a declaration in scope and by using the object it's already been defined. ;)

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

Do some research on virtual memory and paging. The answer is that active pages will use RAM while inactive pages will be moved to hard disk space until needed. Provided there's sufficient hard disk space to hold the inactive pages, the OS will behave as if there's infinite memory (at the cost of performance in moving pages around).

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Introduction to Algorithms by Cormen, Leiserson, and Rivest is a good start. They use pseudocode for the implementation details.

semicolon commented: Thank you +0
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

It places a value on the top of the stack. The equivalent would be:

; push [arg]
sub esp, 4
mov esp, [arg]

Conversely, pop will do the opposite:

; pop [arg]
mov [arg], esp
add esp, 4
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Try to remember your first steps.

Sorry dude, but you'll get no sympathy from me on that front. The resources you have at your disposal would have given me a woody when I was first learning.

This is not an answer: "Use loops".

Did you learn anything at all from the code I provided? You pass the size of the array from the function that it was declared in because array parameters aren't actually arrays, they're pointers, and the size information is lost.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I think that's quite enough of the "me too" joke offerings to do it for money.

nitin1 commented: you are also well in cracking jokes, ;) +2
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I'm willing to be that count and totalwords are both int too, which means your division is performed in integer context. If the division results in a value less than zero, the precision is ignored and the result will be 0. You want something more like this:

int wordpercent = (int)((count / (double)totalwords) * 100)

This forces the division into floating point context, which retains precision so that it isn't lost before the multiplication step.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

The exact same way you do there.

Wait. You're saying that the syntax and semantics of loops don't change from function definition to function definition? That's just crazy talk. ;p

WaltP commented: You know me -- crazeee +14
nitin1 commented: yes! i also know you ;) +0
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Ahh but if I do that, what happens when I access the values in the body?

If the parameter names are the same as the data member names, the parameters will hide the data members when unqualified. This ambiguity doesn't exist in the initializer list, and it can be corrected in the body by qualifying with this:

this->x = x;
this->y = y;
Point(this->x, this->y); // But Point(x, y) works too since the values are the same
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

The choice and reason are both trivial: pick the language you're most comfortable with, because it's easier to stand up a working project quickly when you're not fighting with your tools.

sss93 commented: Thanks and yea I totally agree with your statement +0
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

You can, but my immediate question is why do you want to do so? There has to be a purpose for any level of indirection, otherwise it's just pointless complexity.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

@deceptikon: Is there a way to find out if there were any stickies before the move to the new forum?

Yes indeed. It appears there was one sticky as of July 2011, which I've re-stickied.

pritaeas commented: Thanks. +0
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I find it odd that the implementation supports streams yet not completely. If the hardware couldn't handle stream behavior (presumably this is an embedded platform) then excluding that part of the library entirely would be expected. Rather, I don't recall any clauses in the ISO standard that say tellg() may be conditionally supported in the presence of an otherwise working iostream library, even for freestanding implementations.

But to the matter at hand, istringstream is really doing nothing more here than breaking the line down into fields and converting those fields. Since you already know that the >> operator is whitespace delimited, you can get the same value as stream.tellg() by counting delimiting whitespace for the first four fields:

getline(file,line);
{
    std::istringstream stream(line);
    UINT32 file_pos, fields;

    stream >> first >> second >> third >> forth;

    for (file_pos = 0, fields = 0; file_pos != line.size(); ++file_pos) {
        // Assuming fields are separated by only a single delimiter
        // and the line doesn't begin with whitespace. These are
        // fairly easy to handle, but I'll leave it to you.
        if (isspace(line[file_pos])) {
            if (++fields == 4)
                break;
        }
    }

    fifth = line.substr(++file_pos , line.length() - stream.tellg());
}
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Is this true or can I actually do this in C++?

One of the reasons why this is reasonable in Java is the lack of default arguments. In C++ you can do it all with one constructor:

Rectangle(int width = 0, int height = 0, int x = 0, int y = 0)
    : width(width), height(height), x(x), y(y)
{
    // Nothing necessary in the body
}

Note that I swapped x and y with width and height. For one thing I think it makes more sense conceptually, but also to support the second variant of Rectangle() from your Java code more easily.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

The problem is that there are too many open files.

That's indicative of a design flaw. You can check the value of FOPEN_MAX (defined in stdio.h), and it's probably rather large for your implementation. If you exceed that value, you probably need to consider why you have so many files open at once and think about ways to avoid that.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

The using directive pulls in every visible name from the namespace while the namespace qualified name is visible only for that single use of only that name. Obviously if your goal is to avoid naming collisions in multiple namespaces, a using directive is the worst possible choice and a qualified name is the best possible choice.

However, that doesn't mean qualified names are always better. It's fairly obviously that qualified names are more verbose. You can also limit the scope of the using directive. The following is much less likely to clash names than a using directive at file scope:

void foo()
{
    using namespace NameSpace;

    ...
}

Finally, there's a third choice in the using declaration:

using NameSpace::Method;

This is something of a combination of a using directive and a qualified name in that you're only pulling in that single name, but you're doing so for all uses of the name after the declaration rather than just a single use.

Such as, are there any performance gains with one or the other etc...?

Don't concern yourself over performance here. If there's a difference, it'll be negligible and limited to compile time.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Wow, could you get any lazier?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Unless you're forced by a very backward teaching institution to use Turbo C, or you're maintaining legacy code that must be compiled using Turbo C, GCC (a recent version) is very clearly better.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Also i would like to know the other methods of doing this.

My solution would probably be a double reversal. First reverse the entire string character by character (ie. "daS mA I"). Then go over the string again and only reverse each word. The end result is that the word order is reversed, but the characters in each word are normal (ie. "Sad Am I").

I'd also tighten up the definition of a word to just alphabetic and numeric characters. That way any punctuation can be ignored in the second step and retains the original position. But that's straying a bit from the problem definition and may need tweaking if it's not the desired result:

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

void reverse_string(char *begin, char *end)
{
    while (begin < end) {
        char temp = *begin;
        *begin++ = *--end;
        *end = temp;
    }
}

char *word_begin(char *s) { while (*s && !isalnum(*s)) { ++s; } return s; }
char *word_end(char *s) { while (*s && isalnum(*s)) { ++s; } return s; }

int main(void)
{
    char s[] = "The quick brown fox jumps over the lazy dog";
    char *begin = s, *end;

    reverse_string(s, s + strlen(s)); /* Reverse everything */

    /* Reverse individual words to restore them */
    while (*begin) {
        begin = word_begin(begin);
        end = word_end(begin);
        reverse_string(begin, end);
        begin = end;
    }

    puts(s);

    return 0;
}
nitin1 commented: good approach uses! +0
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

inheritance (n):

  1. something that is or may be inherited; property passing at the owner's death to the heir or those entitled to succeed; legacy.

  2. the genetic characters transmitted from parent to offspring, taken collectively.

  3. something, as a quality, characteristic, or other immaterial possession, received from progenitors or predecessors as if by succession: an inheritance of family pride.

  4. the act or fact of inheriting by succession, as if by succession, or genetically: to receive property by inheritance.

  5. portion; birthright; heritage: Absolute rule was considered the inheritance of kings.

Ask a real question next time, thank you.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Is salting passwords even necessary?

I consider it necessary and would question anyone who doesn't, given how easy it is to add a salt and the security boost of doing so.

iamthwee commented: Thanks for the feedback +14
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

lol.. okies.. now imthewee it's you turn.. come back.. where are you? we are waiting for you here. come on!!

Since you don't seem to be taking the hint, I'll lay it down in no uncertain terms. We know that you're nitin1 and you're doing a piss poor job of pretending that you're not. If you can't let things go, why did you delete your account in the first place?

If you deleted your account because you couldn't change your name, for future reference any moderator can do that for you if you ask. If you deleted your account in protest, I can assure you that nobody cares.

On a side note, every one of us has done or said something we regret, but you don't need to delete your account and start over. Despite how it may feel to you, your embarrassing moments are easily forgettable to everyone else. Unless you habitually repeat the same mistakes over and over, everyone will quickly forget about past transgressions because they're simply not that important.

p.s. No, I won't explain in further detail every word I've used in this post. :rolleyes:

iamthwee commented: Nods +0
nitin1 commented: i think you are correct! +0
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Alternatively, and this would be my preferred option, you can use the KeyPress event to disable that key entirely:

private void textbox_KeyPress(object sender, KeyPressEventArgs e)
{
    if (e.KeyChar == '\'')
        e.Handled = true;
}
Mike Askew commented: The better option by far. +4
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Honestly, I think having extra steps just to vote (ie. click to open the dialog, then click to vote) would turn people off to voting. The quickness of the present system encourages votes.

As for the confusion of which arrow the hover box is representing, perhaps adding an up or down arrow in that little box to make it more clear what you're doing?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Hover over an arrow to add a comment and reputation. Click the arrow just to vote. The arrow you click on or hover over determines if it's positive or negative.

Aside from making a dummy dialog (which would ultimately be less user friendly as popups usually are) instead of splitting the two options with a hover over, I don't think we can simplify it any further. Though I'm open to suggestions. :)

deceptikon 1,790 Code Sniper Team Colleague Featured Poster
bool? my_var = null;

Of if you like being verbose:

Nullable<bool> my_var = null;
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Why a text box? That forces you to validate essentially unchecked input. If you don't want to use radio buttons, how about a dropdown menu with M or F?