Narue 5,707 Bad Cop Team Colleague

Did you try declaring the variables a, b, and c? :icon_rolleyes:

Narue 5,707 Bad Cop Team Colleague

Essentially, all the people who post without code tags would instead get frustrated and/or confused and simply not post at all.

It's this focus on quantity over quality that drives clueful people away from Daniweb and attracts the dregs of the geek community.

I am hesitant to follow in the footsteps of sites such as CProgramming, as that site has been around MUCH longer than DaniWeb, and hasn't seen anywhere at all close to the growth or traffic that we have. Perhaps this is one of the reasons why.

The code tag test is a relatively new addition to cprog, and hasn't affected activity at all. Further, the quality of first posts has increased drastically since that measure was introduced. You know how I feel about Daniweb, but I won't hesitate to say that cprog is a much better community in terms of quality. Daniweb used to be better, and has gone down the tubes in recent years such that now all you'll find on the first page are necros, cheaters, leeches, and morons.

Now, I'm not advocating code detection because I think it's less valuable with the high volume and variance in language options. My personal opinion is that addressing the source of the issue would be more effective than treating the symptoms.

People don't use code tags for one of two reasons: laziness or ignorance. A solid tutorial on code tags (Daniweb has a rather more robust and obscure system than most forums) that's easy …

Narue 5,707 Bad Cop Team Colleague

Addressing the error only (there are other issues), you're passing wname, which is an array of char. The function expects only a single char, not an array of them.

Narue 5,707 Bad Cop Team Colleague

>Yeah i understand how to do that, and my code isn't faulty in that aspect.
Bullshit. Your code is as faulty as the "logic" of believing that your code isn't faulty when it clearly doesn't work.

>And the way ive done it makes sense to me that it should work but
>for some reason (which i cannot find) it does not do what i want.

You're the only one it makes sense to, of that I can assure you. I think my favorite line in terms of sheer lunacy would be this one:

while((input[i] = getchar())!= i < 80 && '\n')
Narue 5,707 Bad Cop Team Colleague

>but if you're passing in the address of a pointer, how is that a copy of the pointer?
Pointers aren't magic. A pointer is just a variable, and the value of that variable is an address. You wouldn't expect the following to print 12345, would you? The idea is exactly the same:

#include <stdio.h>

void foo(int x)
{
    x = 12345;
}

int main(void)
{
    int x = 0;

    foo(x);
    printf("%d\n", x);

    return 0;
}

Adding a level of indirection seems to make people forget the most fundamental concepts of C.

Narue 5,707 Bad Cop Team Colleague

Use fgets to read each line, then your favorite CSV reading algorithm to separate the fields. Here's one easy way to do it if you're not using a complex form of CSV:

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

int main(void)
{
    FILE *in = fopen("data.txt", "r");
    char line[BUFSIZ];

    if (!in) {
        perror(NULL);
        return EXIT_FAILURE;
    }

    /* Poor main's CSV input (doesn't consider embedded commas) */
    while (fgets(line, sizeof line, in) != NULL) {
        char field[BUFSIZ];
        int offset = 0;
        int n;

        while (sscanf(line + offset, "%[^,\n]%n", field, &n) == 1) {
            printf(">%s<\n", field);
            offset += n + 1;
        }

        puts("");
    }

    fclose(in);

    return EXIT_SUCCESS;
}
Narue 5,707 Bad Cop Team Colleague

I'm not sure what drug you guys are taking that kills brain cells, but it seems like everyone and his brother is having trouble with passing pointers to functions and changing where they point to.

But here's an example that does what you want (without using dynamic memory, for simplicity). Compare with what you have and try to locate the differences:

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

int user_input(int *array, int size)
{
    int n = 0;

    while (n < size)
    {
        char input[81];
        int i = 0;

        printf("->");

        /* Be sure to check for EOF as well as '\n' */
        while ((input[i] = getchar()) != '\n' && input[i] != EOF)
        {
            i++;
        }

        /* '\n' or EOF found immediately */
        if (i == 0)
            break;

        /* Always terminate your strings */
        input[i] = '\0';

        /* atoi is evil, but that's another lesson */
        array[n++] = atoi(input);
    }

    /* We need to know how many integers were saved */
    return n;
}

int main(void)
{
    int array[10];
    int n = user_input(array, 10);
    int i;

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

    return 0;
}
Narue 5,707 Bad Cop Team Colleague

I think you should only work on one ADT library at a time unless you're already experienced with the task (which you clearly are not, no offense).

Narue 5,707 Bad Cop Team Colleague

I see quite a few issues, but the most immediate is a misunderstanding of how pointers work when passed to a function. Your initMyString will completely fail to do what you're expecting because the parameter is a copy of the argument, not a reference to it.

See this article for more details. Fix that and we can talk about further issues. ;)

Narue 5,707 Bad Cop Team Colleague

>This is weird, if not creepy.
More like creepy, if not outright disturbing. Even more so in Dani's case due to easy to find real world contact information. At least when crazy stalkers start breathing heavy around me, I'm less frightened because they're unlikely to show up at my doorstep.

Narue 5,707 Bad Cop Team Colleague

>I can't set m->verts[m->numverts] to NULL because at the point before
>if (!m->verts[m->numverts]) , m->verts[m->numverts] doesn't exist

You do realize how ridiculous this sounds, right? "I can't set the object to null because the object doesn't exist when I test it for null". If your code is as whack as I'm seeing and you're describing, it's a wonder it works even some of the time.

Narue 5,707 Bad Cop Team Colleague

>Sometimes they're being set to other addresses but still being unitialized, and
>they pass tests like if(!ptr), causing an unhandled access violation error.

That's the whole point, genius. If you're trying to use an uninitialized pointer, that's a Bad Thing™, and it should be immediately fatal as it's a programming error.

>But I can't set m->verts[m->numverts] to NULL because it hasn't been
>allocated yet and for some reason it's getting set to 0xfdfdfdfd.

I fail to see why you can't set m->verts[m->numverts] to NULL . Your statement suggests a misunderstanding of the difference between a pointer and the memory it points to.

Narue 5,707 Bad Cop Team Colleague

Yes, you can buy motherboards that have multiple CPU slots. How do you think we managed multiple cores before multi-core processors came out? ;)

cwarn23 commented: Excellent information and gr8 news for me! +6
Narue 5,707 Bad Cop Team Colleague

>Yes you were right... lol
That's usually the case. ;)

>and hey, am not a fool
I didn't say you were. I said that only a fool blames the compiler first, though it could be expanded to "only a fool blames the compiler first...more than once". I think everyone needs to get burned by their ignorance one time before realizing that PEBKAC[1] is vastly more likely than a compiler bug.

As I often say in these situations, compilers are mature and heavily tested pieces of software, written and used by extremely computer literate people. The chances of a relative beginner finding a compiler bug in all but the most obscure and little used areas of the language are vanishingly small.


[1] PEBKAC - Problem Exists Between Keyboard And Chair

Narue 5,707 Bad Cop Team Colleague

>Is this Program Correct? or is there more conditions to check..?
No and no, respectively. Your algorithm for the leap year condition is correct, but your code has a little to be desired.

>#include <conio.h>
This header is completely unnecessary for this program. I highly recommend you get out of the habit of including unnecessary non-portable libraries.

>void main(void)
main has returned int for about 60 years. It looks like this:

int main(void)
{
  /* Your code here */

  return 0;
}

Or if you're accepting command line parameters, this:

int main(int argc, char *argv[])
{
  /* Your code here */

  return 0;
}

Nothing else is acceptable if you're a beginner.

>clrscr();
I hate this for two reasons:

  1. clrscr is not a portable function, which means you've limited your code to the compiler that it was written with. Further, clrscr is unnecessary in this situation, so you've needlessly destroyed portability.
  2. Clearing the screen at the beginning of the program is either pointless or antisocial. If you're running the program from an IDE, the output window is owned by the IDE and nothing will precede your first explicit output anyway. If you're running from the command line, removing the entirety of output from previous programs will piss off damn near everyone who uses your program.

>printf("\n\n enter a year::");
While I'm sure it works fine on your compiler and system, output is only guaranteed to be displayed …

vinitmittal2008 commented: so helpful info :) +1
Narue 5,707 Bad Cop Team Colleague

>Thanks for the help, but I was doing it right
If you expected a reassignment of rootNode in AppendNode to change rootnode in main, you were doing it wrong.

>I did not think it was a coding error, looked more like compiler issue to me.
Only a fool blames the compiler first. Your code doesn't match your expectations. It's a misunderstanding of pointers, not a compiler issue.

>either way value of i and thus of *p and thus of **p is changing.
Yes! So you've got the basic concept down, now you need to apply it to pointers instead of integers. Instead of changing the value of i, change what p points to. I can guarantee that the only way you'll be able to manage it is by assigning to *pp. My second example illustrates what your code was doing with wrong(), and what your code should be doing with right().

hyperion commented: I am not really a fool, just caught with some oversight :D +4
Narue 5,707 Bad Cop Team Colleague

>How could a JFrame, an image file, a video file or a text file etc...
>be represented by only a bunch of 000000's and 1111111's?

0 and 1 are really just a convenient notation for the electrical pulses a binary computer uses to generate streams of data. Those pulses are interpreted by a chain of consumers which convert the bit stream back and forth between different representations.

How can something as complex as an image be represented by a stream of 0's and 1's? By combining them into an equally complex language suitable for consumption by a display driver which then determines which pixels on a monitor to light up. When you really think about the complexity of the whole system, it's a wonder that computers work at all.

>Is it good or bad to think this way for a first year student?
It's good to understand such low level things, but probably not until a solid base in more practical matters is built. Keep it on the back burner, but don't stress too much about pretending that some things work by "magic" until you're in a better position to learn how they really work.

islam-morad commented: Great post, Thanks +1
Narue 5,707 Bad Cop Team Colleague

>Narue, how did you self-teach yourself?
A lot of reading both books and magazines. When I got regular web access, I dug through tutorials, articles, threads, and blogs. I read and wrote a lot of code. I talked to any programmers I could and asked questions. After learning the basics, I started teaching others what I knew to solidify my own understanding.

>How long would it take (How many hours studying per day for how many months/days) to reach a level
>where you can land a high paying job (and by that you mean jobs that pay like 100k+, right?)

Time is relative. It all depends on how much effort is spent in learning and, to a lesser extent, how much talent one has. I got my first job after about two years, but it wasn't high paying. My second job was above average but also not high paying.

Both "low paying" jobs gave me the experience necessary to get my third job which was high paying, so the entire process from zero to a high paying job (and by that I mean 80k+) took approximately seven years. I've been programming as a hobby for about fifteen years, and professionally for thirteen.

In terms of effort, programming was practically an obsession until maybe 2006.

Narue 5,707 Bad Cop Team Colleague

>But even after AppendNode call, rootnode is NULL.
Yes, because any changes to rootnode within AppendNode will not persist back to main. In AppendNode, rootNode is a copy of the pointer, not a reference to it. I suspect you need more study on how pointers work between functions:

#include <stdio.h>

void foo(int *p, int **pp)
{
    printf("foo()\n\tp:   %p\n", (void*)&p);
    printf("\tpp:  %p\n", (void*)&pp);
    printf("\t*pp: %p\n", (void*)*pp);
}

int main()
{
    int i = 123;
    int *p = &i;
    int **pp = &p;

    printf("main()\n\tp:   %p\n", (void*)&p);
    printf("\tpp:  %p\n", (void*)&pp);
    printf("\t*pp: %p\n", (void*)*pp);
    foo(p, pp);

    return 0;
}

The way to pass a reference to an object in C is by passing a pointer to that object. Notice how the address of the pointer p in foo is different from the address of p in main. That's because foo's p is a copy of the pointer, a completely different object. If you change where p points to in foo, p in main doesn't change unless you pass a pointer to p (ie. pp), and modify the dereferenced object:

#include <stdio.h>

void wrong(int *p)
{
    p = NULL;
}

void right(int **p)
{
    *p = NULL;
}

int main()
{
    int i = 123;
    int *p = &i;
    
    printf("%snull\n", p == NULL ? "" : "NOT ");
    wrong(p);
    printf("%snull\n", p == NULL ? "" : "NOT ");
    right(&p);
    printf("%snull\n", p == NULL ? "" : "NOT ");

    return 0;
}
Narue 5,707 Bad Cop Team Colleague

>Anyway do you think it's true that if you have 'truck driver' on your resume IT people will not hire you?
No, it's not true.

>That's my dad's logic but I think it's absurd
Yes, it is absurd. A gap in one's employment history would be far worse than a job in another field in terms of raising red flags. The former could cause your resume to be automatically rejected. In fact, a job in another field can be a good thing if the employer is smart enough to recognize transferable skills. If you spent two years working the cash register at Wendy's I'd rather know and assume you have people skills than assume you were sitting on your laurels for two years watching The Price is Right.

>I heard that if you get hired as a SE in Cali you don't have to worry about being out of
>work because if you are fired from one company you can immediately jump to another one nearby.

Not taking into account the saturation of the market and competition for jobs in a weak economy? I'm very confident in my abilities, but getting canned right now would make me sweat a little.

Narue 5,707 Bad Cop Team Colleague

> What about those who are not famous...how can they prove that they deserve
> to get a job as well paying as 100k like CS grads from prestigious U get?

I'm self-taught, and not famous, yet I didn't have any trouble landing a high paying job multiple times. Assuming you've got the skills to demand top level salaries, all you need to do is get an interview.

Narue 5,707 Bad Cop Team Colleague

>and it's still not working.
Useless information.

>I need (char**) because the malloc and realloc returns void right?
It's not needed in C. That conversion is implicit.

>I tried with and without it, none works
Then you're compiling as C++.

Narue 5,707 Bad Cop Team Colleague

>Private data members cannot be accessed outside the class.
Yes.

>When a class inherits a base class, all the data members except the private get inherited into it.
Private members are inherited, but not accessible from the child class.

>So if we want data members to be accessible to only derived classes
>and not privately or publicly accessible, then we can use protected.

While not incorrect, this answer is the kind of cookie cutter thing you'd get right out of a textbook. It shows knowledge, but not necessarily understanding.

A better answer would give a practical example for using protected, explain why it's preferred, then derive a more general guideline from the explanation. This covers all bases in that it shows you can think of a good situation where protected makes sense (understanding of the concept), defend the decision (understanding the pros and cons versus alternatives), and draw a logical conclusion (show creativity and independent thought).

Narue 5,707 Bad Cop Team Colleague

You only need to realloc the first dimension, then malloc the newly added pointers. In this case only one new pointer is being appended to the "array", so it could be as simple as this:

res = realloc(res, sizeof(*res) * count);
res[count - 1] = malloc(z);

<insert caveats about realloc and testing allocations for failure>

Narue 5,707 Bad Cop Team Colleague
Narue 5,707 Bad Cop Team Colleague

>are there any specific video tutorials for people like me ?
Doubtful, and I wouldn't trust them if I knew of any. As a system analyst, your recommendations will be made on a case by case basis and somewhat subjective based on your experience. Much like with programming there are guidelines, but more often than not you'll discard the guidelines to achieve better results.

In other words, for jobs like this where it's more art than science, you're not likely to find step by step instruction that's worth a damn.

>i heard a system analyst can easily become a DBA with 1 or 2 courses from oracle, is that true
A good system analyst should be sufficiently skilled to land at least an entry level DBA job. You're expected to have a broad range of skills, and enough depth in each of them to be competent.

kvprajapati commented: nice. +0
HELL DRAGON commented: thanks alot +0
Narue 5,707 Bad Cop Team Colleague

Are you high? What makes you think anyone but God can help you with a question like that?

Fbody commented: :confused: I agree! +4
Narue 5,707 Bad Cop Team Colleague

>And in relation to the code I posted, why couldn't I have the '\n'?
If there's whitespace in the format string, scanf will extract whitespace characters (any whitespace character, so '\n' is no different from ' ' or '\t' in both the stream and the format string) until the next non-whitespace character. You're essentially requiring input to end with non-whitespace, which is the opposite of what normally happens in line buffered I/O.

Narue 5,707 Bad Cop Team Colleague

>I just wanted to check i was doing the right thing
Very rarely is there one "right thing". I can think of at least half a dozen ways to tackle the problem you were having, and I can guaran-damn-tee that kind of insight doesn't come from having other people solve your problems for you.

>Otherwise it would take many posts if it didnt work
And imagine how much you could have learned in that process that you have now missed out on...

Narue 5,707 Bad Cop Team Colleague

*sigh*

int a = 25;
wchar_t buf[80];

swprintf(buf, L"%d", a);
MessageBox(NULL, buf, L"Sel Change", MB_OK);
Narue 5,707 Bad Cop Team Colleague

The cast to a wide string type should raise red flags. Perhaps you should consider wchar_t and swprintf from the get-go instead of trying to drop narrow characters into wide holes and hoping for magic.

Narue 5,707 Bad Cop Team Colleague

Endianness is about byte order, not bit order. So

00000000 00000000 00000000 00000011

in little endian is

00000011 00000000 00000000 00000000

in big endian. Keep that in mind when doing your conversions.

Narue 5,707 Bad Cop Team Colleague

>I saw this question in a site and tried to solve this but I have no idea can you help me?
If you tried, then show us your attempt and what you learned from the failure. This is pretty close to the easiest of recursive problems, so I'm inclined to think that you gave up far too easily, if you tried at all.

On a side note, this is an extremely poor use of recursion. Any kind of linear progression (or similar slowly decreasing problem sets) should be avoided in favor of iteration because the chance of stack overflow increases drastically when number of expected stack frames is potentially large.

Narue 5,707 Bad Cop Team Colleague

Basic info is basic. ;) Since this is now a sticky, I'd like to see the addition of a common class of examples that tend to cause confusion:

for (int i = 0; i < N; i++) {
    for (int j = i; j < N; i++)
        System.out.println("What be the complexity?");
}

It's O(N^2), but the reason isn't immediately obvious because those not comfortable with Big O focus on the variance of the inner loop rather than the upper bound. A thorough analysis would be an amusing aside, if you feel so inclined.

Narue 5,707 Bad Cop Team Colleague

>i would like to know more about the book before i buy it.
FYI, TAOCP consists of several volumes, and it's concentrated awesome. If I could only keep one of my books (I have many), it would be TAOCP (probably volume 3).

>Reviews as to how the Math in it is
Intense, but if you're not a math head you can still get a lot out of the books.

Narue 5,707 Bad Cop Team Colleague

>Is seems C++ does not have a stream class that supports a read/write in the same open mode.
You should do a little more reading on open modes with the fstream class. Read/write mode is both supported and common. The only caveat is the same as with C streams: when switching between read and write mode, there needs to be an intervening flush or seek.

Narue 5,707 Bad Cop Team Colleague

>which books is most efficient for a totally beginner to programming, C++?
That really depends on you. Everyone learns differently; a great book for one might not be as good for another because of the way concepts are taught. Given a list of recommendations, the ideal is to have a bookstore or library where you can sample all of them and choose the book you're most comfortable with.

>Do they HAVE to be new?
Anything from circa 2000 and newer should be safe. Prior to that you risk getting a book which fails to conform properly to the C++ standard.

>Which other books you recommend - after - the "basic" book/s?
The book sticky lists all of the essentials, if I recall correctly. Also anything recommended or highly recommended here would serve you well.

Narue 5,707 Bad Cop Team Colleague

Define "help", because it looks a lot like you want someone else to solve it for you.

Narue 5,707 Bad Cop Team Colleague

7-bit ASCII is a strict subset of UTF-8, no conversion of values is necessary.

Narue 5,707 Bad Cop Team Colleague

Just one question, what were you expecting to happen with this?

for(int i=0; i<a.elements; i++)
    delete[] &a.element[i];

All you need to do is the inverse of what you did to allocate the memory:

void deallocate(GrowableArray &a)
{
    delete[] a.element;
}
Narue 5,707 Bad Cop Team Colleague

Include the <string> header.

Narue 5,707 Bad Cop Team Colleague

>It looks that u have not understood the question.
I don't understand either. I'd wager that the problem isn't with us, it's with your ability to ask a coherent question.

Narue 5,707 Bad Cop Team Colleague

>what is the difference between Code Goddess and code monkey?
The difference is my business cards don't say code monkey. :)

Narue 5,707 Bad Cop Team Colleague

>so programmer is junior programmer while software engineer is senior?
Potentially. The same problem exists though: different people will define these terms in different ways. Perhaps both junior and senior programmers are code monkeys where the only difference is the complexity of assignments. Often "senior programmer" refers to a programmer on the way to becoming a manager.

>and can you not use the term code monkey
No.

>i just don't want to get referred to as a monkey that's all
I suggest you grow thicker skin, because whining about things rarely changes them. Consider this thread a life lesson in not being a pussy. :)

Narue 5,707 Bad Cop Team Colleague

>then i dont need the part get option of the presudocode?
You're summarizing those steps rather than enumerating them, so I'd say what you have is fine.

>how can i test a code that has no right n wrong .
You misunderstand. There are no rules to pseudocode, but your logic can be faulty. The tests are for your logic rather than correct code. Come up with few test cases, and run them through the pseudocode to verify that the behavior is as expected. Here's an example of a test case:

1) Start the program
2) Enter an option not in the menu

Expected result: 
    Whatever you designed for this case, but 
    an error message and repeating the request
    for input is generally good behavior.

Take the test case and follow the steps of your algorithm as closely as you can. Then come up with as many test cases as needed to make you comfortable that the logic is correct for all possible execution paths.

Narue 5,707 Bad Cop Team Colleague

>i dont no if its right im trying
Didn't I already say there's no right or wrong with pseudocode? As long as the logic makes sense, you're solid. What you posted makes sense.

Narue 5,707 Bad Cop Team Colleague

So the problem is something of a misunderstanding of C-style strings. I'd recommend not using read and write (in general, actually, because they're only safe for POD types) and read each data member individually:

//dat.read ((char *) &data, sizeof(data)); //should read data
dat.get(data.name, sizeof data.name);
dat.get(data.lastname, sizeof data.lastname);
Narue 5,707 Bad Cop Team Colleague

You need to compile GradeBook.cpp as well. Only headers need not be compiled:

g++ main.cpp GradeBook.cpp -o main
Narue 5,707 Bad Cop Team Colleague

>ive got notes but without proper explanation the notes is partly useless
You haven't asked your teacher to explain the parts you don't understand? That's what he's paid to do, after all.

>i didnt ask to give me the whole answer but a guide of how to approach this.
Actually, since this is the most basic of basics, I'd essentially be teaching you how to program. I'm afraid it's rather difficult to cram three months of prerequisite education into a forum post, and I'm actually not good at teaching the basics (I'm more of an intermediate/advanced teacher).

So try something, anything. Break the problem down into steps as if you were explaining how to do something to a very stupid person (which a computer is akin to). I'll get you started:

Start
Repeat Until Done
    Show Menu
    Get Option
    Run Option
Narue 5,707 Bad Cop Team Colleague

Most likely your strings aren't being terminated with '\0'. What does the file look like?