deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I don't have any at the moment. Since you seem to like videos, try searching YouTube for linked list tutorials. I'm sure you'll find something decent enough with plenty of hand waving.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

This thread is for ideas only. The actual code snippets would be created as articles here.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Where will the responses be going? In this thread?

What do you mean by responses?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Here's a better example, see if it helps:

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

struct node {
    int          data;
    struct node *next;
};

int main(void)
{
    struct node *head = NULL, *temp;
    int data;

    printf("Enter a number (0 to stop): ");
    fflush(stdout);

    while (scanf("%d", &data) == 1 && data != 0) {
        temp = malloc(sizeof *temp);

        if (!temp) {
            perror("Error allocating memory, terminating...");
            break;
        }

        /* Prepend the new node to the list */
        temp->data = data;
        temp->next = head;

        /* Make the new node the head of the list */
        head = temp;
    }

    while (head) {
        printf("%d", head->data);

        if (head->next)
            fputs(" -> ", stdout);

        /* Safely free the current node */
        temp = head->next;
        free(head);
        head = temp;
    }

    putchar('\n');

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

ok if time complexity increases will that algorithm be a flop????

Not necessarily, but an algorithm with poorer time complexity must be used judiciously. For example, you wouldn't use bubble sort for a general sort function because it has quadratic complexity and will perform badly on larger data sets. That's why any general sorting function in production quality libraries will use an algorithm that's at least O(n logn) in the average case.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

for wat reason we are taking time complexity into account????for wat purpose???

To give us an idea of how the algorithm scales as the amount of data grows.

bcoz all programmers cant take less steps for finishing an algorithm

I'm unable to translate your meaning from that sentence.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Video uploads seem emminently impractical to me. On top of the size issue (even small videos are relatively gigantic), and latency of retrieving the files, there's also the problem of playback for various formats.

If we implemented something even remotely like this, at the very most it would be tags to directly embed a YouTube player for playback rather than actual upload onto our servers.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

sum() and displaysum() are both member functions. You need an add object.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

So how can I skip '\n'

An easy and somewhat obscure way is to prepend your format string with whitespace. The %c specifier doesn't trim leading whitespace like most of the other specifiers, but literal whitespace in a format string tells scanf() to read and discard all whitespace. So you can get the same trim effect like so:

while(feof(input)==0){
    char c;
    int num;
    fscanf(input," %c%d",&c,&num);
    printf("%c:%d\n",c,num);
}

And to fully handle the sentinel at the end of the file, add a conditional around your output:

while(feof(input)==0){
    char c;
    int num;

    if (fscanf(input," %c%d",&c,&num) == 2)
        printf("%c:%d\n",c,num);
}

Finally, to avoid the feof() problem and also handle the sentinel in one swell foop, use the result of fscanf() as your loop condition:

char c;
int num;

while (fscanf(input, " %c%d", &c, &num) == 2)
    printf("%c:%d\n", c, num);
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

A segmentation fault is when you try to access memory outside of your address space, or protected memory that you don't own. It's nearly always the result of a bad pointer or array index value, so checking those values should be your first line of attack.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

but why we don't use printf()?

Allow me to make an enlightening comparison from my own stdio library. The back end to putchar() is fputc(), which totals in at 22 lines of code. fputs() is built on top of fputc() and is all of 6 lines.

The guts to printf() are pushing 1,000 lines of code.

print() is a very heavy function that does a lot of work. If all you need to do is print a string or character directly, there are simpler functions that do this without any extra rigmarole.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

but result in console is not same as txt file

The line break after each number in your file is a character too. scanf() first reads 'A' and 7 correctly, then prints them. Next it reads '\n' as the character part, but fails the integer part because 'c' isn't a valid decimal digit. You don't do any error checking, so the new character ('\n') and the old integer (7) are printed.

You can easily prove that this is happening by also printing the return value of scanf(). scanf() returns the number of successful conversions, or EOF if no conversions took place, so it should always print 2 or EOF:

while (feof(input)==0){
    char c;
    int num;
    printf("scanf() returned %d\n", fscanf(input,"%c%d",&c,&num));
    printf("%c:%d\n",c,num);
}

But it doesn't. It prints this:

scanf() returned 2
A:7
scanf() returned 1

:7
scanf() returned 2
c:5
scanf() returned 1

:5
...

The fix is to correctly recognize the presence of the newline character and handle it.

On a side note, feof() is inappropriate for controlling a loop because it only returns true after you attempt to read input and fail. Unless there's also a test within the loop body to stop processing of failed input on end-of-file, you'll end up processing the last record of a file twice.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Why is the system reading only one when 12 can be easily represented in a single byte.

Because you asked scanf() for a char, not an int. It interprets the character representation of the key that you pressed, in this case '1'. The thing is that all input is in the form of a string. scanf() will do a string to xyz conversion where xyz is whatever type you requested, and it won't try to convert any more than that.

If you request a string or character, no conversion takes place. 12 becomes "12\0" as a string or '1' as a character (because '1' and '2' are separate characters). If you request an int, then "12" will be converted into 12.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Bit representation of 12 is 00000000 00000000 00000000 00001100.

12 has nothing to do with this. You may have typed 12, but scanf() read the numeric value of '1' and stored it in the first byte. Note also that depending on your system's endianness, the "first" byte may be either the most significant or least significant since scanf() is working directly with memory addresses and not endian-corrected values.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

That's what you get when you lie to scanf(). Assuming 4 byte integers, a looks like this (the question marks mean an indeterminate value):

[?][?][?][?]

Now when you pass the address of a into scanf() and say that it's a pointer to char, scanf() will do exactly what you asked and only fill in the first byte:

[d][?][?][?]

Now when you pass a into printf() and try to get the integer value, you get garbage because the remaining 3 bytes are still uninitialized. It's really no different in terms of undefined behavior than if you just did this:

int a;
printf("%d", a);
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

what is size_t in this??

size_t is a typedef representing the type returned by the sizeof operator. It's very often used as the type for array indices because the maximum value of size_t will never be less than the potential number of indices in any array.

can't we take it as int because we are just passing the size which is an integer??

Yes, you can use int instead.

and could you please explain this part too??

When you type a backspace character, both the last actual character stored in the string and the last displayed asterisk need to be removed. fputs("\b \b", stdout) will handle the latter by first printing a backspace (which isn't destructive, it only moves the cursor), then one space character to overwrite the character being removed, and finally another backspace to place the cursor in the correct position.

Removing the last character from the string is even easier because all you need to do is decrement the index and the character will be overwritten on the next iteration. But there's one edge case where the index is already 0, and you don't want it to go negative or bad things happen.

These two tasks work together to keep both the password string and the display in sync when you type a backspace.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

It looks okay aside from the class name not being fully qualified in your definitions. They should look like this (notice the template argument is included on the class name):

template <class T>
T add<T>::sum(T x,T y)
{
    a=x;b=y;
    return a+b;
}
template <class T>
void add<T>::displaysum()
{
    cout<<endl<<"sum is "<<right<<a+b;
}
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

tm has now this value.tm_hour=17, tm_min=30. I want this value to be stored in time_t datatype to use difftime.

Then use mktime() to generate a time_t out of a tm structure. As long as the structure is valid, mktime() will give you a valid time_t conversion, otherwise it'll return (time_t)-1.

The time library is actually very simple as far as usage (the internal implementation can get hairy though). time() gives you the current time. gmtime() and localtime() convert a time_t into a tm structure. mktime() converts a tm structure into a time_t, and also normalizes out of range values for most of the fields.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Since you've sidestepped the command shell's conveniencies like being able to edit your input before sending it to the program, that functionality needs to be duplicated within your program. In this case that means recognizing and handling the any special characters that the shell normally handles for you:

#include <stdio.h>
#include <conio.h>

char *get_password(char *buf, size_t n)
{
    int done = 0;
    size_t i = 0;

    while (!done && i < n - 1) {
        int ch = getch();

        switch (ch) {
        case '\r':
            /* Convert CRLF to a newline */
            putchar('\n');
            buf[i++] = '\n';
            done = 1;
            break;
        case '\b':
            /* Roll back a previous character */
            fputs("\b \b", stdout);
            fflush(stdout);

            /* Don't underrun the buffer */
            if (i > 0)
                --i;

            break;
        default:
            putchar('*');
            buf[i++] = (char)ch;
            break;
        }
    }

    buf[i] = '\0';

    return buf;
}

int main(void)
{
    char buf[BUFSIZ] = {0};

    fputs(get_password(buf, sizeof buf), stdout);

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

The link I gave provides the same guide in various formats. Pick the one that suits you (I chose to purchase the book), the information is pretty much the same.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

sir, Can you give how nested loop are helping in this ?

There's an implicit loop in next_permutation(), and you call it multiple times (ie. in a loop) to get all permutations. That's nested loops right there.

can you give a algo?

next_permutation() is a template function. Open up the <algorithm> header for your compiler and read how it works. In fact, doing this is better than just being given an algorithm because it forces you to read and understand code so that you can derive an algorithm for porting to other languages.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Beej's Guide is pretty much all you'll need.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Although I agree that is the proper way to handle something like this, the question says to use nested for-loops.

Given that this is the C forum and the link was for a C++ function, I'll go out on a limb and suggest that np complete was recommending that you look at the implementation of next_permutation(). Every one I've seen uses an iterative approach for maximum efficiency.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I wasn't really suggesting you go back to BBCode, but simulating their code tags.

I didn't think you were suggesting BBCode, no worries. We do have an extended Markdown library that implements fenced code tags, but it proved finicky after release and was disabled.

If you parser sees "[code]" then it should know it's code, but when it sees 4 spaces your parser doesn't know whether its normal text or code.

I think you're confusing the code detector with actual code block parsing. The former is for enforcing code tags when they're absent while the latter is for highlighting text within valid code tags. The code highlighting part is working, but detecting likely code in untagged text is a harder task that's practically guaranteed to have false positives. This thread is about those false positives, so adding fenced code tags is a non-solution as it doesn't address the problem at hand.

when it sees 4 spaces your parser doesn't know whether its normal text or code.

The rules for code tags are

  1. The line begins with four spaces or a tab.
  2. The previous line is a code line, a blank line, or the editor boundary.

The highlighter gets this right, as far as I'm aware. I spent a lot of time tweaking it to suit Daniweb's needs.

It makes sense that if a line begins with four spaces or a tab, but the previous line isn't valid, we should raise the code detection …

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

What is the meanig of <> ?
NOT EQUAL?

Yes. = also does double duty as assignment and comparison in that pseudocode syntax.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Try calling the sin() and cos() functions from the cmath header.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

time_t is the number of seconds since 1 Jan 1970 to the specified date.

While it is indeed the canonical epoch, there's no guarantee that time_t represent the number of seconds since 1/1/1970. For example, I very seriously considered using 1/1/1900 as the epoch for my time.h library, to the point where it was functional, before changing my mind and conforming to convention.

Anyway, a good technique for setting up the tm structure when you only care about the time portion is to initialize it to the current day:

time_t t = time(0);       // Get the current datetime as time_t
tm *info = localtime(&t); // Break it down into a local calendar object

// Update desired fields
info->tm_hour = new_hour;
info->tm_min = new_min;

// mktime normalizes the calendar object
if (mktime(info) != (time_t)-1) {
    // info is now safe to use
}
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

hii decptikon if ur der please give me a solution

I require that you make an attempt first. The problem statement is also ambiguous. Are you reversing the bits in each nibble or swapping the nibbles? Anyway, without actually solving the problem for you, I can help you visualize the bits of a value with a simple test program:

#include "stdio.h"
#include "limits.h"

/*
    @description:
        Prints the bits from value in the range of [first,last) to stdout.
*/
void show_bits(unsigned long value, unsigned first, unsigned last)
{
    if (first > sizeof value * CHAR_BIT || 
        last > sizeof value * CHAR_BIT)
    {
        return;
    }

    while (last-- > first) {
        putchar((value & (1U << last)) ? '1' : '0');

        /* Break at the byte boundary for better presentation */
        if (last % CHAR_BIT == 0)
            putchar(' ');

        /*
            Break at the nibble boundary too. This places a
            double break at the byte boundary.
        */
        if (last % (CHAR_BIT / 2) == 0)
            putchar(' ');
    }

    putchar('\n');
}

int main()
{
    unsigned long value = 0x1B;

    /* Display all bits in the value */
    show_bits(value, 0, sizeof(unsigned long) * CHAR_BIT);

    /* Display the first 7 bits */
    show_bits(value, 0, 7);

    return 0;
}

Using this you can actually display the bits directly. Such a function is very useful when experimenting with bit manipulation.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

any other book same as the introduction to algorithms ,deceptikon

I used to collect programming books, but I've since cleaned house and sold the majority of them. However, the data structure and algorithm books I still keep on my bookshelf related to C are:

  • Algorithms in C (Robert Sedgewick)
    The material is first class, but the code is absolute shit. However, I firmly believe that one can learn a lot by fixing the bugs.

  • Practical Algorithms (Andrew Binstock & John Rex)
    I have this one more for the code than anything. It's not great code, but not bad either, and I imagine it would be an informative book for a beginner.

  • Practical Algorithms in C++ (Bryan Flamig)
    This is my favorite on algorithms. Great book.

  • Practical Data Structures in C++ (Bryan Flamig)
    This is my favorite on data structures. Fantastic book.

  • Data Structures and Algorithms in C++ (Adam Drozdek)
    I actually haven't read this one... I had an older version that focused on C and upgraded to the latest edition in C++. I just haven't had the time to work my way through it. But from what I've seen, it's pretty decent.

I'm actually not a huge fan of CLRS, mostly because I don't find its contents inspired at all, which makes reading it boring. But if you're not familiar with the subject, CLRS is definitely the most recommended book.

If you read and understand this book, you will be very …

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

30 minutes, IIRC.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

asrockw7 Thanks man. but your adivise for proffissnal not bigiiner like me ^^

Um, no? Breaking a problem down into manageable pieces and experimenting with ideas in a small and controlled environment is programming 101. It's something every beginner should be learning on their first day, and a skill that everyone should be using regardless of experience level.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I'll answer your comments directly:

// Should I malloc memory for ptr_ex here before assigning values to it???

Yes. An unintialized pointer is not a pointer to usable memory, you must first point it to memory that you own either through dynamic allocation or through the address of an existing variable.

Though in this case you don't need a pointer. You can simply create an instance of the structure and pass its address to myfunc().

//Can I directly deference the values below???

Provided that myptr points to a valid object and the object has been initialized with non-garbage values, yes.

or should I malloc memory for *myptr also???

No. The assumption here is that the calling function owns the memory for this pointer and has set everything up properly for you to use it without worrying about managing memory.

I_m_rude commented: excellent explaintion... +2
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

does that means that order in which i write the structures elements matter to calculate the offset and hence size changes?

Yes. My personal preference is to order members in a way that makes intuitive sense at a higher level than padding and alignment, but that's just a general guideline. I've been known to optimize the organization of my structures when the situation warranted it. ;)

also 3 bytes are free here.. isnt it memory wastage though small?

This is one of many places where you'll encounter the speed vs. space tradeoff. At the cost of a few bytes, the performance can be improved by a statistically significant amount.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

how performance is increased?

Values can be loaded into memory and registers more quickly when they're suitably aligned. Otherwise the system might have to calculate an offset from a native boundary to get to the correct address.

are structure elements location in memory contiguous?

Barring padding, yes.

if yes, in this case then there is free memory blocks after char variable as size is greater than individual sum?

In this case I'd wager that there are 3 bytes of padding after q so that w is properly aligned on a word boundary. So the structure looks like this in memory:

[q][?][?][?][w][w][w][w]
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

What does the tree look like?

Why should that matter? As long as it's a valid binary search tree, the algorithm won't change depending on how the tree looks.

Can anybody share the algorythm to perform inorder traversal of a binary search tree using parent node(without stack or recursion)

As long as you save the encountered node, it's a relatively simple matter of using the value of the previous node to determine where to go next. For example (pseudocode):

while it <> null
    if prev = it.parent
        prev = it

        if it.left <> null
            it = it.left
        else
            visit(it)

            if it.right <> null
                it = it.right
            else
                it = it.parent
        endif
    else if prev == it.left
        prev = it
        visit(it)

        if it.right <> null
            it = it.right
        else
            it = it.parent
    else if prev = it.right
        prev = it
        it = it.parent
    endif
endwhile
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Members of a structure may be aligned to certain byte boundaries to improve performance or if the platform simply doesn't allow an object of a certain type to begin at any byte. Also, and partially to facilitate alignment, there may be padding between members of a structure or at the end of the structure.

So unless you go out of your way to pack a structure (using non-portable methods), its size will likely be more than the sum of its members' sizes.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

It's a very straightforward usage of function pointers. Here's a quikie example using a stack:

#include <stdio.h>
#include <stddef.h>

#define CALLBACK_MAX 10

typedef void (*callback_t)(void);

static callback_t callbacks[CALLBACK_MAX];
static size_t n = 0;

void register_callback(callback_t callback)
{
    if (n == CALLBACK_MAX)
        return;

    callbacks[n++] = callback;
}

void run_callbacks(void)
{
    while (--n < (size_t)-1)
        callbacks[n]();
}

void foo(void) { puts("foo!"); }
void bar(void) { puts("bar!"); }
void baz(void) { puts("baz!"); }

int main(void)
{
    register_callback(&foo);
    register_callback(&bar);
    register_callback(&baz);

    run_callbacks();

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

It was much simpler and safer to just use CODE tags.

The detection algorithm is intended to alleviate the problem of posting code without code tags. That problem exists whether the tags are implemented as BBCode or Markdown, and it's not a trivial problem due to the myriad programming languages that Daniweb supports.

and sometimes it guesses wrong.

To be honest, I'm not a huge fan of the algorithm either (I didn't write it, and the way it works is not how I would have written it). At one point I tightened it up a bit by ignoring 4+ spaces and tabs as long as they weren't at the start of a line, but that was rolled back for reasons that I've since forgotten.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Here's a very simple example of what I was talking about:

#include <ctime>
#include <iostream>
#include <sstream>
#include <string>
#include <tuple>

using namespace std;

time_t make_time(tuple<int, int> new_time)
{
    time_t now = time(0);    // Find the current time
    tm *info = gmtime(&now); // Convert it to calendar info

    // Update the minute and second
    info->tm_min = get<0>(new_time);
    info->tm_sec = get<1>(new_time);

    // Convert back into a time_t (fixing errors in the process)
    return mktime(info);
}

tuple<int, int> parse_time(const string& s)
{
    istringstream iss(s);
    int min, sec;

    // Naive parsing, assumes the string is valid
    iss >> min;
    iss.get();
    iss >> sec;

    return make_tuple(min, sec);
}

int main()
{
    time_t time_in, time_out;
    string s;

    cout << "Enter player time-in between 08:00 and 17:00: ";
    cin >> s;
    time_in = make_time(parse_time(s));

    cout << "Enter player time-out between 08:00 and 17:00: ";
    cin >> s;
    time_out = make_time(parse_time(s));

    cout << "Play time was " << difftime(time_out, time_in) << " seconds\n";
}
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I don't see code here, why is it being detected as such?

The detection algorithm presently looks for four spaces, a tab, or curly braces anywhere in the post.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I'm curious how these two approches actually test for valid values.

At least for strtod(), a combination of the return value and end pointer as the second argument can be used to validate the string. If conversion stopped before the end of the string, then it's not valid.

I'm not sure about the latest implementation of boost::lexical_cast, but originally it was based on a stringstream and you could test for error or eof status.

Of course, there might be a remaining issue if the OP wants to validate an arbitrary length value, because strtod() and boost::lexical cast are limited to the size of a double for the implementation.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

because we have a single array

Yes.

and we dont split into two different arrays

Actually, that's not true. You'll notice that in the naive algorithm, the array is partitioned and then each subarray separated by the pivot gets recursively quicksorted. So conceptually at each recursive call you're sorting a unique array. That those arrays happen to share the same memory as one bigger array is irrelevant to labeling the algorithm as divide and conquer.

As an example, take the array {5, 3, 7, 2, 1, 6, 0}. Assuming a perfect partition, we'd select 3 as the pivot and partition the array into something like {0, 2, 1, 3, 7, 5, 6}. Then the array is subdivided into two smaller arrays: {0, 2, 1}, and {3, 7, 5, 6}. Repeat that process until (at least in the naive algorithm) you have as many subarrays as there are items, and the top level array will be sorted.

Here's the whole process on that set of numbers:

{5, 3, 7, 2, 1, 6, 0}
{0, 2, 1, 3, 7, 5, 6}
{0, 2, 1}{3, 7, 5, 6}
{0, 1, 2}{3, 5, 7, 6}
{0}{1, 2}{3}{5, 7, 6}
   {1}{2}   {5, 6, 7}
            {5}{6, 7}
               {6}{7}
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

wat is that clrs book??

Introduction to Algorithms.

can u send a e-book copy

As far as I'm aware, there's not a free version. You'll either have to buy it, or acquire a pirated copy from somewhere else as such discussion violates Daniweb's rules.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I see we've come full circle. You were given code that presumably works with only minor corrections to make it portable to your compiler. Have you even attempted to fix the code that raj so kindly gave you? Or are you expecting us to write the whole thing in its entirety for you so that all you need to do is turn it in for a grade?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Boobies? In Hackers?

Yup. Brief, but memorable enough for a kid in the 90s.

I meant Sneakers.

That's a good one too. I was trying to remember where James Earl Jones was in Hackers. :D

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Take a look at the ctime header. It includes types and functions for manipulating dates and times. With minimal effort you can parse your time string into a tm structure, convert those into time_t objects with mktime(), and finally get the difference with difftime().

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I was hoping by leading you to the "You can't" conclusion I would bring back my initial request

Which would in turn bring us back to my intitial reply. You didn't lead me to concluding that there's something wrong with the voting system, it's working as designed.

can we get a checkbox or comment box (maybe it should be mandatory to down vote?), so we can see why we are down voted instead of useless responses?

Votes aren't useless, they're a trend metric for determining a member's overall perception among the community. What you're looking for already exists as the reputation system, where comments are required. You're expecting something out of the voting system other than what it was designed for, so the answer to your request, at least for now, is no.

As for being mandatory to down vote, you can't force people to comment if they don't want to comment. They'd just type gibberish or useless comments and we'd be right back at square one.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I think youre missing the point...

Sorry, I assumed that the answer would be obvious given my initial reply.

How can I find why someone down voted me?

Unless they choose to leave a comment, you can't. That's the point; votes are a weak form of reputation, they're both very general (ie. either "I like this post" or "I don't like this post") and largely anonymous.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

The ability to vote on your own post is infinitely abusable, so we disallow it. ;)

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

There's already an optional comment for votes that also applies reputation points. When you click on either an up or down arrow, the comment box will pop up.