deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Dude, I'm not against helping you, but you need to read our rules:

Keep It Organized
  • Do provide evidence of having done some work yourself if posting questions from school or work assignments

If you continue to post nothing but homework questions without any evidence of thought or effort on your part, I'm going to start deleting.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

i don't understand the question its bonus question

What part don't you understand? You're supposed to write a program that accomplishes the stated goal, and the question even tells you how to implement it. Since this is a homework/classwork question, I'm not going to do it for you, but I'll be happy to help you understand any specific problems with the question itself, or any specific problems you have with your code.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Please provide evidence of having attempted to solve this homework question on your own.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

data.read(reinterpret_cast<char*>(corpData), sizeof(corpData));

This is an exceptionally bad idea because the Division type (of which corpData is an array) contains non-POD object types, std::string to be precise. You can't safely treat non-POD types as sequences of bytes for two very importan reasons:

  1. The structure of the object is dependent on many things, and internal "dead space", or padding, can create trap representations that will likely crash your program.

  2. Classes that manage dynamic memory internally won't be able to reproduce their structure or data simply by xcopying bytes from a file into an object that's not specifically prepared for the data. This is the most likely cause of your current crash.

I strongly recommend that you take a step back and do I/O in a simpler manner. Instead of trying to pun your data into a sequence of bytes, write and read each element of the array in a precise manner, field by field. It might be more tedious because you can't use a one-liner like read() or write(), but it's much safer.

An alternative is to support a serialize() and deserialize() process in your Division objects. This would produce a sequence of characters that can be safely read and written using the binary one-liners of read() and write().

So to summarize, these two lines are broken and need to be replaced with a different solution entirely. There's no way to make them safe as-is:

data.write(reinterpret_cast<char>(corp), sizeof(corp));
data.read(reinterpret_cast<char
>(corpData), sizeof(corpData));

Sendy Hipo commented: thx :D +0
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

No offense, but while I could do your debugging for you and tell you exactly what the problem is and how to fix it, you wouldn't learn jack from that. Given that this is the first of many, many, many access violations you're sure to encounter, you'd benefit greatly from learning how to troubleshoot the problem on your own in a very simple program.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

The error you're getting typically means there's an access violation. Access violations are typically caused by invalid pointers, so your first line of attack should be to step through your code in a debugger and keep a close watch on your pointers to make sure that they're valid at any given time.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Assuming you meet the requirements of LGPL, it seems that way. This is cool, I wasn't aware Qt had moved to an open source library model. That's what had kept me from using it. :)

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

As I have tested in VC++, if I use queue from <queue> and call any of these functions for an empty queue, program crashes.

If the queue is empty, what were you expecting a reference to by calling front() or back()? This is a case of undefined behavior, which is largely why the empty() member function exists.

Could this problem be solved by simply adding a throw, in case when queue is actually empty, so front and back would throw an exception which'd be caught by try block?

Assuming we're moving away from std::queue and into your own implementation of a queue, that would be an acceptable solution.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

toupper() both accepts and returns an int to account for EOF. You need to assign that result to a char or cast it before printing:

writefile << (char)toupper(ch);
Sendy Hipo commented: nice! +0
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Can you post a complete program that exhibits the problem? cout should be smart enough to treat chars and strings differently from integer types, so I suspect the snippet given isn't entirely accurate compared to what you're actually testing.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

If all you're doing is excluding the 'b's then it's as simple as this:

for (i = 0; i < length; i++)
{
    if (writtenStuff.charAt(i) != 'b')
    {
        Console.out.print(writtenStuff.charAt(i));
    }
}
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

You can use mktime() after populating a tm object with the suitable date. Then the comparison can be done with difftime():

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

time_t get_today(struct tm** date, int is_gmt)
{
    time_t now = time(NULL);

    if (date)
    {
        *date = is_gmt ? gmtime(&now) : localtime(&now);
    }

    return now;
}

time_t get_date(struct tm** date, int is_gmt, int year, int month, int day)
{
    struct tm* working_date;
    time_t ret = get_today(&working_date, is_gmt);

    working_date->tm_year = year - 1900;
    working_date->tm_mon = month - 1;
    working_date->tm_mday = day;

    if (date)
    {
        *date = working_date;
    }

    return ret = mktime(working_date);
}

int main(void)
{
    int year = 2012, month = 6, day = 20;
    time_t today_time = get_today(NULL, 1);
    time_t target_time = get_date(NULL, 1, year, month, day);

    if (target_time == -1)
    {
        fprintf(stderr, "Invalid date: '%d-%d-%d'\n", year, month, day);
        return EXIT_FAILURE;
    }

    if (difftime(target_time, today_time) < 0)
    {
        puts("Your trial period has expired");
    }
    else
    {
        puts("You are using a trial version of this software");
    }

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

Allow me to deconstruct the code into what I believe are the relevant lines:

CImg <float> inImage(inputImage, image_width, image_height);
float *WrappedImage, *UnwrappedImage;
WrappedImage = inImage;
free(WrappedImage);

If CImg handles its memory internally as one would expect, I see nothing good coming out of that call to free().

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

That totals to 5,978,160 bytes (assuming 8-byte double). Not horrible, but something to think about, especially if you can devise a way to avoid keeping all of those values in memory if you don't really need them.

Now to answer your question:

  1. Yes.
  2. God yes. Doing this manually is uber painful.
  3. Read the following at your own risk:

    #include <vector>
    
    using namespace std;
    
    typedef vector<double> vec1d;
    typedef vector<vec1d> vec2d;
    typedef vector<vec2d> vec3d;
    typedef vector<vec3d> vec4d;
    
    int main()
    {
        vec4d v(115, vec3d(4, vec2d(114, vec1d(114))));
    
        for (int i = 0; i < 115; ++i)
        {
            for (int j = 0; j < 4; ++j)
            {
                for (int x = 0; x < 114; ++x)
                {
                    for (int y = 0; y < 114; ++y)
                    {
                        v[i][j][x][y] = 0.0;
                    }
                }
            }
        }
    
        // ...
    }
    
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Tested, confirmed, fixed, and pushed to staging. It should make it to production today or tomorrow. Thanks for the report. :)

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Try calling perror() after fopen(). I notice you're not checking to see if the file was successfully opened before trying to read from it.

mcjiwe commented: Thank you so much =) +0
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

You're getting that error because pointers aren't magic. If you want a pointer to point to N bytes of memory, you must ensure yourself that the memory exists and assign the base address of that memory to the pointer.

The specific problem here is that you're using uninitialized pointers as the destination objects for scanf(). scanf() expects there to be sufficient memory (which in and of itself is problematic with the %s specifier and no field width) when no such memory exists.

erik's suggestion will work, though it will certainly lead to that problem I mentioned briefly concerning %s without a field width. Alternatively you can allocate memory to the pointers with malloc(). However, I think a better solution would be using "large" buffers to hold each string and then allocate just enough on a case by case basis:

char login[1024];
char pwd[1024];

while (fscanf(fp, "%1023s[^=]=%1023s\n", login, pwd) == 2) {
    user[u].login = strdup(login);
    user[u].pwd = strdup(pwd);
    ++u;
}

I made a few changes:

  1. Each %s is now given a field width to ensure that buffer overflow doesn't occur.
  2. Instead of testing for EOF, I test for 2 (the number of expected matches) to account for formatting errors in the file.
  3. Two input buffers are used instead of the destinations at user[u]. Then user[u] is filled in using the non-standard strdup().
  4. A minor nit: while it's unlikely to make a difference, prefix increment is conceptually faster and more intuitive.

Since strdup() is a non-standard function, here's an …

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

It's not "working". When you lie to printf() you invoke undefined behavior, which could result in a seemingly valid value being printed.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Posts are retained forever unless they break the rules and are subsequently deleted. As for how long it takes to get a response, it very much depends on the nature of the question and the forum. Some forums are very active while others are less so.

If you don't get answers promptly, it could be because nobody knows the answer, nobody has time to answer, your question wasn't clear, or not many people have seen it yet. I notice you posted a question in the C forum, which is fairly active. You've also got a reply to that thread asking for clarification. ;)

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

if fflush(stdin) is not the best way to flush input stream, what is?

The best way to flush the stream is to not need to flush it in the first place. ;) Most of the time you'll get recommendations to read a line in full using fgets() or some variation, then parse that line in memory using sscanf(). This is the single best way to keep the stream clear.

However, it would be foolish to suggest that you'll never need to clear the stream, in which case a decent facsimile of fflush(stdin) that's conformant to the C standard is as follows:

void clear_line(FILE* in)
{
    int ch;

    clearerr(in); /* Required as of C99 */

    do
    {
        ch = getc(in);
    }
    while (ch != '\n' && ch != EOF);

    if (!feof(in))
    {
        /* Only clear non-EOF errors for the caller */
        clearerr(in);
    }
}

The only problem with this is that it doesn't account for an empty stream. If you call clear_line(stdin) and the stream is empty, it will block for input and then ignore the input, so it's not exactly like fflush(stdin). Unfortunately, there's no standard way to simulate fflush(stdin) completely.

Finally, the problems with fflush(stdin) are very real, but if you're using a compiler that supports it and if you don't plan on moving to a compiler that doesn't, any complaints about it are strictly on principle. The only reason I mentioned it as a problem at all is the majority of people who advocate …

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

There are many here who can help you when you ask a specific question, but nobody will do your project for you.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

IT SHWS BGI ERROR :GRAPHICS NOT INITIALISED (USE 'INITGRAPH')

Click here for a solution to your problem.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Do you have a question?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

If format strings are not supposed to be like "%c abc", then why doesnt scanf terminate and return 0 when it encounters this type of format string?

You can have format strings like that, and they're occasionally useful. But it's important to understand the purpose of a literal match and how scanf() will behave.

I simply wanted to know what happens when you put the abc after %c.

%c is a placeholder for any character and it will be stored in the corresponding variable. "abc" will be matched literally and if it's not matched then scanf() will stop reading at that point. You'll only notice the effect if trying to extract more placeholders or by looking at the contents of the stream after scanf() returns. For example:

#include <stdio.h>

int main(void)
{
    char ch;
    int rc;

    rc = scanf("%cabc", &ch);
    printf("scanf() returned %d\n", rc);
    printf("scanf() extracted '%c'\n", ch);
    printf("Next character: '%c'\n", getchar());

    return 0;
}

If you type "gabcxyz" the output will be:

scanf() returned 1
scanf() extracted 'g'
Next character: 'x'

If you type "gxyz" the output will be:

scanf() returned 1
scanf() extracted 'g'
Next character: 'x'

These two tests show that the "abc" part was matched and tossed away, and also that if the literal match fails, nothing is extracted. Now you can test another placeholder:

#include <stdio.h>

int main(void)
{
    char ch;
    int x, rc;

    rc = scanf("%cabc%d", &ch, &x);
    printf("scanf() returned %d\n", rc);

    if …
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Context_b16187_25845991

This post has no text-based content.
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

In C, you must know what you are doing.

Yes indeed.

fflush(stdin) // OR fpurge(stdin) on unix-like OS

Oh, the irony. fflush() is specifically designed for output streams, and if you know what you're doing then you've probably heard that the C standard says calling fflush() on an input stream invokes undefined behavior. If you know what you're doing, you avoid undefined behavior like you avoid that guy walking down the street yelling to himself.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Go ahead and click the button to add reputation, the difference between rep and a mere vote is the presence of a comment. In other words, if you leave the comment blank, it's just a vote even if it comes from the "Vote & Comment" button.

And we'll look into making sure that the comment box actually shows up below the arrows too. ;)

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Also the page containing list of thread where i have posted is also in queue?

Assuming we're thinking of the same thing, yes.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

You need to build the integer value manually using its component bytes:

#include <iostream>
#include <Windows.h>

using namespace std;

int main()
{
    BYTE freeBlocks[4] = {0x00, 0x05, 0x7d, 0xa4};
    DWORD displayValue = 0;

    displayValue = freeBlocks[3];
    displayValue |= freeBlocks[2] << 8;
    displayValue |= freeBlocks[1] << 16;
    displayValue |= freeBlocks[0] << 24;

    cout << displayValue << endl;
}

The reason strtoul() didn't work is because it uses the string representation of a number, not an array of byte values. This would do what you want, but it wouldn't solve the problem you have:

cout << strtoul("359844", 0, 10);

Your output is 0 because strtoul() is failing on invalid input.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

You can tell by the number of replies, the most recent respondant name, and if thread subscriptions are turned on, you'll be notified by email as well. Unfortunately the recent activity icon isn't working quite as we'd like, but that's on the list of things to fix, so it's only temporary. :)

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Update after 4 episodes: Acchi Kocchi and Sankarea are both quite good so far.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

i think the even bigger concern , is the ammount of useful and helpful posts that receive no voting at all, with or without rep.

some of these people are just plain ungrateful :(

Providing answers and help is a thankless job, to be sure. But that makes the thanks you do get all the more rewarding. :)

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

That part of the post doesn't refresh through AJAX, so you'll need to refresh the whole page to see the code highlighting after submitting.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Those errors coming from the use of a library suggest that you aren't properly linking to it. Did you make sure to link to the .lib/.dll file for OpenGL, or just include headers?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

newString.append("//");/*where I actually need doubleslashes */

Do the same thing twice:

newString.append("////");/*where I actually need doubleslashes */

The double slash in string literals is an escaping measure because a single slash represents the starter for an escape character. Thus the escape character for a single slash is two: one to introduce an escape character, and the other to act as the value of the escape character. You can have as many of those escape characters as you want, but it can get confusing when there are just rows of slashes. ;)

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I'm not sure I understand the difficulty. You already have the login credentials and know if they were legit or not, so it should be trivial to toss the user name into a label:

labelLoggedIn.Text = _authenticated ? "Logged In As: " + userName : "Not Logged In";
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

how about bumping threads several years old?

It depends on the context. If it's a reasonable continuation of the thread, all is well. However, if it's just a rehash of the original question or only tangentially related then it should have been posted as a new thread and falls under Keep It Organized.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Unnecessary bumping is frowned upon because bumping sends the last post on page 1 to page 2 (which is tantamount to the kiss of death on Daniweb). But you're correct that there's no rule against it. Legitimate bumping that continues a discussion is fine, though it still annoys certain people. ;)

Special circumstances require special handling of course, and if someone regularly bumps with pointless posts that are clearly for the sole purpose of sending their thread to the top of the list, I'd say that it's fine to close the thread and explain our take on bumping.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Fix it too ;)

Dani doesn't let me publish to the production server, so while I can fix stuff, it still has to go through her approval process before you see it.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I just noticed this as well. Dani has been tweaking the editor and posting process, so something may have gotten through accidentally. I'll take a look.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Can i start making money, even very little from this?

Unlikely. Freelancers are expected to hit the ground running, and if you lack real world experience it'll be even harder finding a gig than a permanent junior position. Sure, you could bid on sites like rentacoder.com, but I wouldn't expect to make any kind of living off of it given that most people there bid stupidly low as a supplement to their day job.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Since constructors can run before main() in C++, order of construction can sometimes be an issue with global and static objects that touch each other. Unfortunately, I'm as stumped as you are, probably more so in that I'm so far disconnected from the actual running code. ;)

Apologies.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Like I said, it was a very unlikely theory. ;) In the actual code, are you by any chance calling somefunct() from a constructor in a global object?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Hmm, interesting. Two things to consider since there's some potential funkiness involved. When you call malloc(), make sure that the correct header is included, and also cast the result as C++ doesn't support implicit conversion from void*. This is all speculation since I haven't used a Borland compiler in ages, but it could be that the lack of a matching definition causes the compiler to assume this:

int malloc(size_t)
{
    return 0;
}

Granted that's unlikely, but it would explain your results. At the very least, making sure the code is C++ compatible would be a start in troubleshooting the issue. :)

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Your job would be vastly simplified by storing the numbers in an array rather than as separate variables. Then you can sort the array and choose the median with ease.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

All admins, moderators, team colleages are employees or some of them just contribute their time to site. And if they are employees how do you work together? at one place?

Any compensation is between the individual and Dani, but to the best of my knowledge the team is mostly composed of volunteers. And only Dani and Kerry work from the Daniweb office. The rest of us are in our respective homes and home lands. We communicate through the forum, private messages, email, and in some cases (such as Dani and I discussing more extensive coding tasks) we speak on the telephone. Daniweb also has events every now and then in New York, for those who are able to travel there and participate, but that's open to anyone and not just team members.

Also Can I ask if you know what happened to Narue?

Narue has decided to retire her account on Daniweb. Sanjay and I will be picking up the slack as the two new admins.

Sahil89 commented: Perfect answer :) +0
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

After watching the first episode, Acchi Kocchi looks promising. I was kind of annoyed when Danshi Koukousei no Nichijou ended, so woot!

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

It was your control panel in vBulletin. The new design is intentionally "plain" because it's only a first version of the system and a simpler design improves both performance and usability. The control panel from vBulletin in particular was excessively complicated and it confused people.

Now that we're relatively stable from the initial bugs, feel free to make feature requests. But please provide a specific description of what you want. Using your description of the lost features, "statistics about traffic income to daniweb for code snippets and stuff like that", isn't quite detailed enough to work out a new feature design.

Philippe.Lahaie commented: +1 for "control panel" ! :D +0
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Am I the only one who feels this way?

Nope. I'm giving the OP the benefit of the doubt though, because it's possible that this has legitimate uses. However there's a strong chance that it's a very naive attempt at virus propagation logic.

Also, wrong forum.

Looks fine to me.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

The concatenation operator for std::string doesn't convert non-string (or character) types to strings. Try this instead:

#include <iostream>
#include <string>

using namespace std;

int main()
{
    string s;

    for (int i=0; i<10000; i++)
    {
        s+="1";
        for (int j=0; j<i; j++)
            {s+="0";}
    }

    cout << s;
}