Narue 5,707 Bad Cop Team Colleague

>You also need to master the basics elements
>such as generics, delegates, interfaces, etc.

I'm a fan of generics, but I don't delude myself into thinking that they're required knowledge. You can get by without writing a single generic class or method and still be an non-novice. Laundry lists of "learn this or you're a n00b13" are quite pointless. The difference between a beginner, a non-beginner, and an expert is much like the difference between bad code and good code. You know it when you see it, but there's not a perfect methodology for sniffing it out.

>Design patterns are, in my opinion, what separate beginners from experienced.
I agree thoroughly. Beginners use design patterns because they lack design experience. Experienced programmers don't need them because they have the requisite experience.

>It impossible to call anyone a professional programmer. May be one in a million.
Erm, not really. A professional programmer is a programmer that gets paid to program. That's the primary definition of "professional". If by "professional" you mean "guru", then I'd agree. Gurus are a myth.

>You can call yourself an expert only when you have the skills and experience
You can call yourself an expert only when a large enough sampling of your peers call you an expert.

Narue 5,707 Bad Cop Team Colleague

>>Foreach works on the string array, not on the function call.
>yeah that is what i concluded and surprised.

Right. No offense, but that's pretty obvious when you consider that the expression for foreach requires some form of enumerable collection. foreach is really just syntactic sugar that's converted to a more traditional loop using an enumerable interface:

foreach ( string s in deneme() )
{
  listBox1.Items.Add ( s );
}

becomes:

{
  IEnumerator e = deneme().GetEnumerator();

  try {
    string s;

    while ( e.MoveNext() ) {
      s = (string)e.Current;
      listBox1.Items.Add ( s );
    }
  }
  finally {
    // System.String is a sealed type; no disposal
  }
}

You can see from the expansion that deneme is only called once to retrieve the enumerable collection, then the loop traverses the collection. No magic, just clever compiler tricks to make your life easier.

Narue 5,707 Bad Cop Team Colleague

>Also, as a side Q, do you define both of these as C-style strings?
Yes. The defining trait of a C-style string is the null character at the end. String literals guarantee its presence.

Narue 5,707 Bad Cop Team Colleague

The fact that it's printing more than twenty numbers should be a strong indication that your condition for the loop in displayArray is incorrect. Specifically, it's written with a C-style string in mind, not an array of float. Try passing the size to displayArray like you do with setArray. That particular condition style won't work unless you have some kind of sentinel value at the end of the array (which you don't).

Narue 5,707 Bad Cop Team Colleague

>why doesn't this code work
Did you define DEBUG?

Narue 5,707 Bad Cop Team Colleague

>because apparently they're out there, somewhere, as optional features with some compiler.
I seriously doubt that. More likely they're teacher-written libraries to protect beginners from the nuances of C during a programming course. simpio.h is suggestive of this, as it indicates a "simplified" I/O library.

>lets see one of you compile his code and debug it.
Done. It took less than five minutes to write a dummy library such that the code can be debugged without any changes to the driver code.

>which is what i was going to do until i realized it
>was going to be an entire project in and of itself.
Really? The more you talk, the more I doubt your programming abilities. Are you honestly saying that replacing the includes with the following stub code is too much for you?

/*
  Begin "non-standard" header implementation
*/
#include <stdlib.h>
#include <string.h>

typedef char *string;

#define New(T) malloc ( sizeof ( T ) )

string CopyString ( string src )
{
    string dst = malloc ( strlen ( src ) + 1 );
    return strcpy ( dst, src );
}

int StringCompare ( string a, string b )
{
    return strcmp ( a, b );
}

size_t StringLength ( string s )
{
    return strlen ( s );
}
/*
  End "non-standard" header implementation
*/

If you flame people and you're right, you'll get a lot more respect than if your flame is so off the mark that it's embarrassing …

Narue 5,707 Bad Cop Team Colleague

>when i tried aux=aux->prox
...aux becomes invalid because aux->prox is an uninitialized pointer. Any further use of aux, except to point it to another address, is doomed to failure.

Narue 5,707 Bad Cop Team Colleague

>Can you explain what is it: binary search tree sorted with quicksort method???
It's a poorly worded question. Clearly a binary search tree is already sorted by nature, so quicksorting the tree itself is nonsensical. By the looks of the code, the OP wants to copy the contents of the tree to an array, then quicksort the array using different comparison criteria.

The question boils down to: "What's wrong with my quicksort algorithm?"

Narue 5,707 Bad Cop Team Colleague

>Who says using brackets is better?
A lot of people. It's recommended in all coding guidelines I've seen and required in the majority of them. The rationale is that if you add statements to a block without braces and forget to add the braces, you've introduced a difficult to find logic error. I follow the careful coding guideline[1] so it's not an issue which you choose as far as I'm concerned, but you'll find that braces around every compound statement is considered a best practice.

[1] Careful Coding Guideline: Turn your brain on before starting and keep it on while writing code.

iamthwee commented: Yes +21
Narue 5,707 Bad Cop Team Colleague

>>...but #include "stdafx.h" is missing
>Please note that it's not needed for non-Microsoft compilers
It's not needed for Microsoft compilers either. :icon_rolleyes: I hate how they use that as a default include for generated code. That's one of the reasons I always create an empty project with Visual Studio instead of using the templates.

Narue 5,707 Bad Cop Team Colleague

>why does anyone use system("PAUSE"); ??
Because it gives you a pretty message? Because teachers teach it? Because beginners don't, and shouldn't be expected to, know the pitfalls of it?

tux4life commented: Bad teaching practice then :P +7
Narue 5,707 Bad Cop Team Colleague

>I use the Turbo C++ 3.0(dont judge it by graphics) as its easier to use.
Then your outdated suggestions are likely to be useless to the majority of people here. C++ has grown since then, and most modern compilers will simply refuse to compile your code.

Narue 5,707 Bad Cop Team Colleague

>i am getting three answers for just one bit on
Can you give me an example? Most likely I'm testing your code based on how it's written, not how you seem to expect it to work. In other words, I can't reproduce your issue.

Narue 5,707 Bad Cop Team Colleague

Simplest solution: store the result values in an array, then traverse the array backward.

Narue 5,707 Bad Cop Team Colleague

Perhaps if you explained exactly what you were expecting and how what you got is different...

Narue 5,707 Bad Cop Team Colleague

>i know there is a way of making that work by allocating memory
>on stack, which is simpler, but you cant do that for large arrays.
That's not one of the ways I was thinking about, because your requirements included variable unknown length. In particular, I was thinking of a linked list, especially since you don't seem to need anything but sequential access. It's actually easier to keep track of linked nodes than it is to maintain capacity and current size for a dynamic array:

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

int main ( void )
{
    struct node {
        unsigned long value;
        struct node *next;
    };
    
    struct node *head = NULL;
    struct node *temp;
    unsigned long value;

    while ( scanf ( "%lu", &value ) == 1 ) {
        temp = malloc ( sizeof *temp );

        if ( temp == NULL )
            break;

        temp->value = value;
        temp->next = head;
        head = temp;
    }

    while ( head != NULL ) {
        temp = head->next;
        printf ( "%lu\n", head->value );
        free ( head );
        head = temp;
    }

    return 0;
}

Of course, that may just be me, as I'm a data structure junkie.

Narue 5,707 Bad Cop Team Colleague

>shu shu shu shut you mouth
You can dish it out, but you can't take it? That's pretty sad.

Narue 5,707 Bad Cop Team Colleague

You've got a massive memory leak. Each time the loop iterates, you replace your pointer with a new block of memory. I imagine you wanted realloc instead of malloc:

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

#define CHUNKSIZE 5

int main ( void )
{
    unsigned long *array = 0;
    size_t capacity = 0;
    size_t n = 0;
    unsigned long value;
    size_t i;

    while ( scanf ( "%lu", &value ) == 1 ) {
        if ( n == capacity ) {
            unsigned long *save;

            capacity += CHUNKSIZE;
            save = realloc ( array, capacity * sizeof *array );

            if ( save == NULL )
                break;

            array = save;
        }

        array[n++] = value;
    }

    for ( i = 0; i < n; i++ )
        printf ( "%lu\n", array[i] );

    free ( array );

    return 0;
}

>dont tell me other ways, i know there are other ways.
That's pretty rude, dude. We're only trying to help you, and if your code for this way is so messed up, you probably don't understand the other ways either. Why are you so against learning?

Narue 5,707 Bad Cop Team Colleague

>I surrender. you are right. I am wrong.
I'm not trying to be right, I'm trying to figure out what the hell your problem is. If you're going to act like a five year old, I'll be happy to treat you like one.

Nick Evan commented: lock it & plonk it :) +18
Narue 5,707 Bad Cop Team Colleague

I'll admit that my first reply to that thread assumed you had gotten a warning prior to asking the question. Now I'm confused as to why you were irritated enough to ask in the first place. Are you just too sensitive to handle honest people?

Narue 5,707 Bad Cop Team Colleague

>Before anyone starts talking about mixing c++ and c,
>I know it's generally a bad idea but std::strings are to slow.
It's not generally a bad idea, but I'm curious why you think std::strings are too slow. Have you written your code using them, profiled it, and determined that the biggest bottleneck is inside the string class? Or are you making a conclusion based on subjective observation and/or hearsay?

Narue 5,707 Bad Cop Team Colleague

>The ancient hebrew scripture and large sections of the bible are actually code.
Any significant body of text will contain "hidden messages" that mean absolutely nothing and weren't intended by the original author. It's no different from how successful prophecies work: if you're vague enough, they apply to damn near anything you want.

Narue 5,707 Bad Cop Team Colleague

>I accidently posted a thread meant for this forum
>and got a tirade of abuse from "you know who".
Please link to the thread you're referring to. Looking at your account, I see you've only started five threads, none of which contain any form of abuse. You've never received a warning or an infraction, and none of your posts appear to have taken abuse either.

All of this "tirade of abuse" and "berating me" came completely out of nowhere. "You know who" isn't helpful either. If you really have a problem with a post, report it as AD suggested. These whines and warnings to others are completely unproductive and unprofessional.

Narue 5,707 Bad Cop Team Colleague

We can't create a forum for every language, but this one is a catch-all for the languages that aren't explicitly mentioned. VBA is sufficiently different from VB 4/5/6 to go there, but other VB questions are probably better suited to the VB 4/5/6 forum or VB.NET.

Narue 5,707 Bad Cop Team Colleague

No forum is exempt from moderation. Perhaps you should read and follow the rules instead of whining about it.

Narue 5,707 Bad Cop Team Colleague

1) Functionally, in that situation, the two are the same. What you're seeing in the first example is C's comma operator in action. Occasionally you'll see people use it to avoid braces. Whether that's a good idea is debatable.

2) div_t is a standard structure. Do you have a more specific question about "what's happening"?

Narue 5,707 Bad Cop Team Colleague

DarthPJB, it's a good idea to not take iamthwee seriously, in pretty much every case from what I've seen.

Salem commented: LOL - that's the truth! +33
Narue 5,707 Bad Cop Team Colleague

>but with only 7-8 people there on average
The same 7-8 people. The whole point of this thread is to increase the awareness of the chat channel and make it better.

Narue 5,707 Bad Cop Team Colleague

You are cordially invited to the #daniweb channel on server irc.daniweb.com, port 6667. We need some new blood to keep the conversations fresh, and what's more fun than chatting with your favorite techies in real-time?

Narue 5,707 Bad Cop Team Colleague

Why don't you help people instead of trying to defend their honor? It's far more productive than making an ass of yourself on your first day.

>I have this thing with not liking people who think there better than everyone else.
I have this thing about not giving a damn what other people think of me. :yawn:

>dont disrespect people that are trying to learn
Respect is earned.

Narue 5,707 Bad Cop Team Colleague

The state of the stream and the contents of the buffer are separate. Even though you reset the buffer to a new string, the stream is still in an end-of-file state from the previous read.

You'll notice that out_offset is correctly set to 3 because the stream starts off in a good state when you create it. But the first time you read to the end of the initial buffer, the eofbit is set and changing the contents of the buffer won't make a difference.

Do a buf.clear(); to reset the stream state.

Clockowl commented: To the point and constructive. +2
Narue 5,707 Bad Cop Team Colleague

>Great Help!!!... sike, be a little more of a bitch next time
You're not looking any better, smart-ass. I love how those most vocal about me not being nice are so hypocritical. :)

Narue 5,707 Bad Cop Team Colleague

Subtract '0' from '2' and see what happens. Then do it for '0' through '9' to verify that it works across the board.

Narue 5,707 Bad Cop Team Colleague

>cout << dist[1][1] << endl; // This correctly displays 0 (not initiallized yet)
Which means either you got extremely lucky, your snippet is misleading and dist has static storage duration, or you're relying on a compiler extension that automagically fills arrays with 0. The following would be more correct:

int dist[2000][100] = {0};

>cout << dist[1][1] << endl; // This incorrectly displays 50
It looks correct to me. You just weren't expecting this behavior. For your homework, I want you to figure out the integer value of the character '2'. You can do this by looking at an ASCII table (which matches your result), or by writing a simple test program that casts the character to an integer.

Narue 5,707 Bad Cop Team Colleague

calloc is essentially this:

void *calloc ( size_t n, size_t size )
{
  void *base = malloc ( n * size );

  if ( base != NULL )
    memset ( base, 0, n * size );

  return base;
}

The difference is that the bytes are set to zero with calloc and left as-is with malloc.

Narue 5,707 Bad Cop Team Colleague

>I have read that this requirement is going to be relaxed in the next
>revision of the standards, but no compilers have implemented that >yet (for obvious reasons)
Mixing declarations and executable statements is a feature that's been available since C99, and quite a few compilers support it.

Narue 5,707 Bad Cop Team Colleague

>but could you tell me the tutorials,examples,
>lessons showing what I have said please
Absolutely not. Discussion of virus writing is against Daniweb's rules. Because you brought up C as a virus writing medium, I'm disinclined to help you at all because now your motives are in question. Try browsing MSDN for the system API for working with Windows.

Narue 5,707 Bad Cop Team Colleague

The char type is an integer type, but when you use the << operator to print it, it's assumed that you want to print the character representation. To get the numeric value you can cast to an integer:

#include <iostream>

int main()
{
  const char *s = "test";

  for ( int i = 0; s[i] != '\0'; i++ )
    std::cout<< (int)s[i] <<' ';

  std::cout<<'\n';
}
Narue 5,707 Bad Cop Team Colleague

>I am new to Daniweb, and I didn't want to search for other people's answers.
Translation: "I'm too lazy to search for something that's sure to exist already."
Alternative Translation: "Even though the questions and answers are exactly the same, they're not mine, and I'm special so I deserve customized personal help."

>I wanted to call someone and get a new interview, and I got that.
How much do you want to bet that you got exactly the same answers a search would have produced?

>What gives you the right to put people down?
I'm a naturally cruel person, it's what I do.

>Does it make you feel better?
Well, now I'm less bored, so the answer to that question would have to be "yes".

>You have no idea what kind of programmer I will be and you shouldn't judge me.
You strike me as the kind of programmer who relies on others to get things done. With any luck my harsh judgment will encourage you to exceed my expectations. If you manage that I'll be thrilled.

>This will be the last time I use this forum.
Guess what? Nobody cares! :) I often wonder why people insist on publicly declaring that they'll never return. It's childish, petty, and really serves no purpose other than to attract attention with the equivalent of "Look at me! I'm stomping off in a huff!".

iamthwee commented: Disagree with the use of bold. -4
Ezzaral commented: I think the bold adds clarity. +22
Salem commented: Just to annoy iamthwee's pedantry +32
Narue 5,707 Bad Cop Team Colleague

>Don't kill me! I'm sorry!
Rawr! ;)

tux4life commented: :D +7
Narue 5,707 Bad Cop Team Colleague

>Someone has helped me.
And that someone was nobody here because we didn't give you everything you wanted on a silver platter? I hate to break it to you, but you don't strike me as a very promising programmer after reading your comments (excuses, really) on this thread.

Narue 5,707 Bad Cop Team Colleague

Did you even bother to read my example? You butchered it beyond comprehension despite the fact that it already does what you're currently asking for. :icon_rolleyes:

[edit]
By the way, I'm merging this into the original thread so you don't confuse the bejeezus out of everyone.
[/edit]

Narue 5,707 Bad Cop Team Colleague

>I mean can I do these kind of stuff just using C programs
Yes.

>can C language be used as a code of virus
Yes.

>if yes how
By typing code into a text editor and then compiling it to an executable file, just like any other program.

Narue 5,707 Bad Cop Team Colleague

Oddly enough, most of the problems with stream input are solved the same way: read an entire line into a string and then parse that line for validity:

#include <iostream>
#include <sstream>
#include <string>

int main()
{
    std::string line;

    std::cout<<"> ";

    if ( getline ( std::cin, line ) ) {
        std::istringstream in ( line );
        std::string command;
        int argument;

        if ( in>> command >> argument )
            std::cout<<"Valid\n";
        else
            std::cout<<"Invalid\n";
    }
}
Narue 5,707 Bad Cop Team Colleague

>I have to interview one-and my options are running out.
Why don't you search the forum for similar interviews? Your questions are hardly unique. I know for a fact that I've thoroughly answered each of them for students looking to interview a programmer.

Narue 5,707 Bad Cop Team Colleague

>Just... please no.
That was terribly informative. :icon_rolleyes:

Narue 5,707 Bad Cop Team Colleague

Since nobody bothered to show you how to get a random floating-point value, here's a complete program to help you out:

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

int main ( void )
{
    int i;

    srand ( (unsigned)time ( NULL ) );

    for ( i = 0; i < 10; i++ ) {
        double r = rand() * ( 1.0 / ( RAND_MAX + 1.0 ) );

        printf ( "%f\t%f\t%f\n", r, r * 10, r * (20 - 10) + 10 );
    }

    return 0;
}

Originally, the value of r is a pseudorandom floating-point value in the range of [0,1). This is represented by the first column of output.

The second column multiplies that value by some whole number, which produces a floating-point value in the range of [0,N) where N is the multiplier.

The third column takes it another step and gives the range a lower bound that isn't zero. Multiplying by the difference between the upper and lower bounds and then adding the lower bound, you can get a floating-point value in the range of [M,N) where M is the lower bound (10 in this case) and N is the upper bound (20 in this case).

I'd also be remiss if I didn't mention that using the result of the time function as an argument to srand isn't guaranteed to work, though you aren't likely to find a system where it fails.

Narue 5,707 Bad Cop Team Colleague

>1) Visual Basic IS REALLY stupid
You can think whatever you want as long as you aren't too foolishly proud to consider it as a viable option when appropriate. I despise Java, for example, but I'm quite skilled with it because I'm smart enough to objectively judge my tools.

>2) No point of view is more important than mine (joking)
Close. No point of view is more important than mine because I've yet to meet someone with enough sense to have a better one.

>3) I will now start learning Java
Good for you. Every language you learn, and every tool you utilize gives you valuable experience that can be applied in seemingly unrelated places.

>4) I will make a PAL of my own, designed in my own way
Best of luck to you.

>6) I still wonder if elite programmers will ever join together
>in a team, in order to create a masterpiece.

I do it every day.

>The idea of a competitive world is not actually what I dream of...
A world without competition is a world without innovation.

>. . Should I try searching for kids like me, who are not necessarily >interested in any money? Or there is no such thing?
Try joining an open source project. Money is rarely the biggest motivator for the best developers.

>Now I know C++ from A to Z and you doubt it. What …

Narue 5,707 Bad Cop Team Colleague

>wat is echo??
In this case, echo means that when you type a character, it prints to the screen so you can see what you typed.

Jignesh07 commented: print series 2,4,16,256..up to n in c lanuage +0
Narue 5,707 Bad Cop Team Colleague

>I am a student, the concept of programming is extremely new to me.
We got that impression, but even if we didn't there's no reason to point it out. Usually the "I'm a newbie" defense is used as a way to preserve one's frail ego when the code gets seriously reviewed and is found to be lacking:

Noob: "Here's my code. Awesome, right? Amiright?"
Us: "Actually, it's pretty bad: <thorough review>"
Noob: "Oh, well I'm new to programming."

>I did my own work...All I wanted was for someone to tell me if I was on the right track.
Nobody suggested that you didn't. But it's quite impossible to tell you if you're on the right track when you refuse to post your code. My psychic powers are pretty good, but not that good.

>I didn't mean to imply that anything that I have done or ever will do is anything "special".
Sure you did. Your code is so special and wonderful that you can't show anyone because it'll be stolen by cheaters the instant you make it publicly viewable. :icon_rolleyes:

>It is amazing how people forget what is was like when they were learning.
It's amazing that this is always the fallback whine of any newbie who feels offended, even if it's completely inappropriate. And for the record, we're all still learning. The learning doesn't stop.