deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Note that this is a dual feature, and the second part makes the first part less useful. If we implement some sort of notification that people are online, we'll also need to include a way to disable it and allow people to be invisible. Otherwise it has too much of a "Big Brother" feel.

Honestly, while I did find it interesting to see whether someone was online, I myself chose to be invisible. Honestly, I'm not sure whether that feature makes sense for Daniweb or if it would be nothing more than feature matching to compete with other forums (which I don't think we need to do).

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

but if i were at your place, then i will prefer "NOT TO REPLY" rather than commenting like this.

That's a good idea. I'll refrain from replying to your posts from now on.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

i don't think that you don't know i "try" things or not.

I made my suggestion and you posted for hand holding help one minute later. I'm reasonably sure you didn't try anything.

But whatever. I've made my suggestion and now it's up to you to implement it. I don't have Dev-C++ installed, so I couldn't give you detailed instructions even if I were so inclined. Best of luck.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

So saying rudely that "just use little comon sense as DEV c++ is not complex" is not good.

Sorry dude, but I have no patience for people who don't even try to do something before shooting back with requests for hand holding. And when I said Dev-C++ isn't complex, I mean it's not complex period. Beginners prefer it for that exact reason, so this isn't a matter of my perspective as a more experienced developer.

Look in your project settings for something that seems promising. Read the documentation. Search the web for instructions. Learning how to use your tools is programming 101. You've been here for a while and know how things work, so I'm going to hold you to a higher standard than J. Random Newbie who shows up out of the blue and has only been coding for half a day.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Find your project settings, find your compiler settings underneath. There should be a text box somewhere asking for other switches or compiler options. Type "-ansi", and rebuild your project. Or look in the compiler settings for a check box that mentions something about "-ansi". Seriously, use a little common sense and just explore your IDE settings. Last I recall, Dev-C++ wasn't very complex, so this shouldn't be diffcult.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Um...no. I want you to add a compiler switch in the settings.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Try using the -ansi switch. You mentioned Dev-C++ earlier, which suggests MinGW, which I recall was broken in some areas of the stdio library.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

i said that solution above is general :D

And I implied that your solution is brittle. ;D

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

So it looks like you're not actually doing a full merge sort, you're just merging together three arrays that are already sorted. Really the only tricky part of this is taking what you know about merging two arrays and extending it into three. Here's a two way merge:

int dst[size * 2], n = 0;

while (i < size && j < size) {
    if (a[i] <= b[j])
        dst[n++] = a[i++];
    else
        dst[n++] = b[j++];
}

while (i < size) dst[n++] = a[i++];
while (j < size) dst[n++] = b[j++];

I'll let you take a shot at doing the three way merge, but there are three steps:

  1. Find the smallest item from the three arrays until one of them is exhausted.
  2. Perform a two way merge on the remaining two arrays until one of them is exhausted.
  3. Exhaust the remaining array, if there are still items.

That means you're essentially taking a two way merge and adding a preliminary three way merge until there are two arrays left. So something like this:

while (i < size && j < size && k < size) {
    if (a[i] <= b[j] && a[i] <= c[k])
        dst[n++] = a[i++];
    else if (b[j] <= a[i] && b[j] < c[k])
        dst[n++] = b[j++];
    else
        dst[n++] = c[k++];
}

After that it's a simple matter to determine which array was exhausted and perform a two way merge on the remaining two arrays.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

The problem is that it's my first project of its kind and i don't know how to start also the defregmant part is a bit tricky

So you haven't been given any projects in the entire course? This is the final project, which means you can't play the clueless card.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

after getchar i use another getchar to clear the buffer

Though there's no guarantee that the second character is a newline, so you're making an unwarranted assumption about the user's behavior.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Pseudocode is just a formalized list of steps, there really aren't any rules beyond generally trying to remain consistent and logically sound.

So your job is to break the assignment into component parts. What steps are involved? What order are the steps in? For example, it's not unreasonable to have user input as the first step because that kicks everything off. So what happens after user input? You need to organize the cause and effect of this program in your mind, then formalize it into steps. Those steps can then be further formalized into pseudocode or a flowchart.

By the way, our homework rule states that you must provide some proof of effort. Just plopping your assignment down and expecting any kind of meaningful help is both nonsensical and a violation of our rules.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Welcome aboard! That's my background as well. I started out as a system admin/IT technician to get my foot in the door and then moved to software development with a focus on .NET and C#. Yes, the learning curve is steep, but that's half the fun. ;)

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

You're aware that this is the very first program anyone learning assembly will have to write, and it's ALWAYS provided in toto by the teaching resource (ie. book, website, or course notes), right?

So either you're lazy to the point that shocks even me, or you need to ask a more specific question.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

It seems like you're looking for a Soundex type of algorithm.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I'm having trouble deciphering that incomprehensible mess. Could you please rephrase your question?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Still a pretty high learning curve for an experiment.

Assuming you'd need to learn how to do the conversion. ;)

I can't see any other code being cost effective in terms of time spent for insignificant or even no gain.

I agree completely. While I can't confidently say one way or another without confirmation from the OP, this whole thread strikes me as excessive focus on performance where there's no real benefit.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Looks fine to me, and works fine on Visual Studio 2012. What compiler and OS are you using?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Please post an example program.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

It's very hard to write code that ends up more efficient than the built-in codes when you're doing conversions.

Actually, it's pretty easy unless you have the same goal of being a general conversion. If you can make assumptions about either the source or destination value you can optimize by avoiding work that the more general algorithm has to do. Often that's exactly what happens when replacing standard library code with ad hoc code for performance reasons.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

if i use "%lf" in printf will it work ?

Only if you're compiling as C99 or later, otherwise %lf is an unsupported format specifier and you invoke undefined behavior.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

then why "%f" in printf ? why not "%lf" ?

Because a float value will be automagically converted to double in a variable length argument list. There's no need for both %f and %lf because there's no difference after that conversion. However, C99 added redundant support for %lf to printf() because so many people were confused that scanf() and printf() didn't have identical rules.

And before you ask, no, a pointer to float is not converted to a pointer to double in a variable length argument list. So I'm not contradicting myself.

nitin1 commented: ;) well explained +2
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

is it what u said ?

Yes.

but i always use %f and it works fine for both cases. please clearify.

Working as intended is one effect of undefined behavior. The problem is that by using %f with scanf() and passing in the address of a double, you're lying to scanf(). %f says that you intend to pass the address of a float, and there's no guarantee that the two types are interchangeable inside scanf().

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

You mistyped the code from the book. The format string for double in scanf() is "%lf", with a lower case L, not 1. For printf() it's just "%f". Adding 1 to either of them introduces a field width, which you probably don't want.

ulrik m. commented: Thank you very much, it works +0
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Can anyone link me to a moderator's profile? need to ask them about something personal.

My profile.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I mean, something that explains theroes very well to the bottom (in short) and cover needed areas in and updated with good questions and answers to them.

That describes just about any recommended book, and all of the ones you listed. I'm dead serious when I say just take a look at all of them in the bookstore and pick the one that feels most comfortable to you.

I don't think Aceelerated c++ covers C++11? is that a problem?

It's not a problem. As far as I'm aware, there aren't any good books out that cover C++11 in any meaningful way. Most of the significant features are what I would consider to be advanced anyway, and have no business being covered in a beginner book.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Will pPath take the value c:\programfiles or c:\programfiles x(86) depending on the os?

Um...yes. That's the whole point of using an environment variable to handle the non-constant path.

If yes, then how should i change

Those arrays should contain just the file name, and you can combine the two as needed:

char path[BUFSIZ];

strcpy(path, NotesDir); /* Push the full folder path */
strcat(path, "\\");     /* May not need this if NotesDir already includes it */
strcat(path, Fname);    /* Add the file name */
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I don't think 7 seconds is outrageous for almost 13 million runs of that loop. Do you have a reason for increasing the speed or is it just premature optimization?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I've not been around these forums long enough to comment really, have I?

Suggestions and comments are always welcome.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

If the elapsed time is greater than something reasonable (say 4 weeks) , prompt the current poster to consider making a new thread or even disallow said posts

We already put up a notification on the quick reply for older threads, any more than that would be excessive, I think.

In addition, if a thread has not been closed after some duration (6 weeks?), would it be possible to close it out automatically with some status such that it would no longer show up in the unanswered listings?

This comes up a lot, and the final word from on high (ie. Dani) is that we want people to be able to continue discussions even if they're old. And my own personal experience from other forums is that automatically closing threads is a horrible solution that stifles the community as a whole.

The problem is pointless bumps with things like "me too" or "thanks for sharing" (usually these end up just being signature spam), and hijacking an old thread with a new question. For those cases the post falls under our Keep It Organized rule and should be reported for moderation.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Unfortunately this isn't the kind of variation that scanf() is designed to handle gracefully. What's happening is scanf() is detecting the sentinel character before saving any characters for a field, thus an empty field denotes failure to perform the conversion for the scanset.

You'll need to check for two adjacent commas outside of scanf() and recognize that as a blank field, then clean up the source stream such that scanf() doesn't fail to match the string. For example using sscanf() (such as if you're pulling the line first with fgets()):

#include <stdio.h>

int main()
{
    const char *src = 
        "DET,1420065,ES,427,VIAJES EL CORTE INGLES S.A.,"
        "C/MAYOR 68,ALCANTARILLA,30820,MURCIA,,968895895,"
        "968893770,,A28229813,N";
    char field[1024];
    size_t pos = 0, n = 0;

    while (sscanf(src + pos, "%1023[^,\n]%*c%n", field, &n) == 1) {
        printf("'%s'\n", field);

        pos += n;

        if (src[pos] == ',') {
            puts("Blank field");
            ++pos;
        }
    }

    return 0;
}

And another using the slightly more awkward (in my opinion) get/unget method if you're reading directly using fscanf() or scanf():

#include <stdio.h>

int main()
{
    char field[1024];
    size_t pos = 0, n = 0;
    int ch;

    while (scanf("%1023[^,\n]%*c", field) == 1) {
        printf("'%s'\n", field);

        ch = getc(stdin);

        if (ch != ',' && ch != '\n')
            ungetc(ch, stdin);
        else
            puts("Blank field");
    }

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

Define "best". Because you're asking for something subjective that is totally irrelevant to your situation. Take a look at both in a bookstore and pick the one that you can follow more easily.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I think everyone understands what you want, but what you want is impossible with the given information. You must store the size somewhere in a separate variable where the size is known if you want access to that size from func().

Somehow I doubt that your embedded compiler supports something like _msize(), but that's an alternative that you need to RTFM to see if something is available.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

when I read it how can I find out there was an endline or not ?

How do you plan to use that information once you get it? That will somewhat determine what method you use. For example, you can run through the file character by character and look for '\n' to answer the simple question of whether a newline is present, but that may not be conducive to whatever you plan to do afterward.

Well if you use getline() it will read in everything in the file until it reaches a newline.

Until it reaches a newline or end-of-file (or an error occurs). So you'd need to check the stream state to be sure that the line ended with '\n' and not EOF.

NathanOliver commented: Thanks for the clarification +10
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Did you click on the link to a getenv() reference I provided in my previous reply? That's how you make use of environment variables, and it's a standard function so every compiler will support it.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Why not get rid of down voting altogether? In reality, and has happened, someone could down vote out of malice, or because they don't know what they are talking about.

Any feature can be abused. Should we punish everyone for the actions of one or two outliers? Concerning the type of abuse you're thinking of, I can remember less than five instances of the same behavior for both voting and reputation in the last seven or eight years. While it's painful for the victims, the number of abuses of the system are vanishingly small compared to the number of legitimate uses.

Why not have a complaints forum, with a moderator that deals with situations in a sincere manner. It has to be sincere too, because if it isn't then there will be a real loss of face and credibility, and more cross-forum "bar brawls". If a user Complains in any forum other than the 'complaints forum, their post can be moved to it and be dealt with suitably. People who have a genuine complaint are looking for a peaceful resolution, and don't mind where it is done as longas justice is seen to be done, or whatever. Trolls would just want to make personal attacks, which is bad enough, but they also do it without any justifiable reason.

I'm not sure I see the benefit of that. If the "complaint" is about a suspected rule violation the post should be reported using our reporting system. If …

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

To make it even clearer, in the C programming language, nothing in the language keeps track of the size of an array. That information does not exist once the array has been created.

You can extract that information, iff you have access to the array object itself (a pointer won't work):

size_t size = sizeof(array) / sizeof(*array);

But that's unlikely to be a suitable answer to the original problem, given that the "array" is actually a pointer (since it's a function parameter). However, I did want to make it clear that the size of an array isn't lost, per se, but you absolutely must be working with the array object itself and not a pointer for sizeof to work properly.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

For paths like this, they shouldn't be hardcoded in the first place. Three options come to mind that are viable and reasonably easy to implement:

  1. Have the user type in the path.
  2. Store paths in a configuration file under the same folder as the executable. Then you can just use a relative path:

    char *NotesDir = strdup(argv[0]); /* Get the full path of the executable */
    char *Fname    = "notes.ini";
    char *Bakname  = "notesini.bak";
    
    /* Trim the executable name from the path */
    *strrchr(NotesDir, '\\') = '\0';
    
  3. Store the paths in the registry.

  4. Store the paths in an environment variable (see below).

I'd probably go with the configuration file for all but the simplest programs, where I'd use user input. The registry isn't really a recommended practice anymore, but it's still fairly commonly used.

Note that the sample code for option #2 makes two assumptions that you'll need to confirm or work around:

  1. strdup() is supported by the compiler's library.
  2. argv[0] gives you the full path of the executable.

Neither of these are guaranteed.

Can an environment variable be used?

Yes, you can use an environment variable. But either the variable needs to be created by your installer, or whoever installs the program needs to add it or the program won't work properly. Basically it's the same deal as a registry key, just in a different place.

Once the environment variable is there though, it's trivial to access using getenv(). The same …

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

What kind of skills / tutorials should I brush up on over the summer to try and gain programming skills that I might need?

You'd need an extraordinary amount of talent to pick up programming well enough over a single summer to be at a professional level. Sorry, but that's just the way it is. You could probably get an excellent head start by getting heads down in a good book on the languages your anticipated job would require, but I think that's the limit.

However, realistically, a good employer will hire someone with promise even if they aren't up to snuff in terms of skills and knowledge. Programming professionally is really just endless on the job training, and a decent recruiter will understand that. I've yet to get a project where I know how to do everything needed to ship on time and on budget.

Can I get a job doing the same real world IT type stuff with a CS degree?

Certainly. In fact, if the IT side is your passion, I'd suggest spending the summer getting a few certifications and target that for your career instead of software development.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

good for all that is written poorly on the interwebz.

That's a guaranteed ulcer. ;)

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Skyrim on the Xbox has been my crutch when I have time between work, university, my kids, and my wife. I love that game.

Skyrim is awesome. But for some reason it doesn't hold my attention as well as Oblivion. Maybe it's because I burned myself out on Oblivion and Skyrim is more or less Oblivion with better graphics. Though the next DLC taking us into Solstheim should bring life to the game for me (at least, I hope).

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

One step forward, two steps back. You're still redefining the arrays inside the loop. Now it's just new variables hiding the ones defined outside the loop. You also always print even[45], which to me is nonsensical.

Compare and contrast:

#include <fstream>
#include <iostream>

using namespace std;

int main()
{
    ifstream in("input.txt");

    if (in) {
        int even[50], odd[50];
        int m = 0, n = 0;
        int value;

        // Read up to 50 numbers from the file
        while (in>> value && (m < 50 && n < 50)) {
            if (value % 2 == 0 && m < 50)
                even[m++] = value;
            else if (n < 50)
                odd[n++] = value;
        }

        // Display the results
        cout<<"Even\tOdd\n";

        for (int i = 0; i < m && i < n; ++i) {
            if (i < m)
                cout<< even[i];

            cout.put('\t');

            if (i < n)
                cout<< odd[i];

            cout.put('\n');
        }
    }
}
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

looks like its still not producing the results needed.

Then start up a debugger and trace through the function. Or you can add debug prints that tell you what each value is at key points in the algorithm. It's important to learn how to debug your code, because someone won't always be around to tell you what the problem is and how to fix it. ;)

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Don't reset upper, lower, and digit inside the loop. You only care that any character matches, so after it's set to 1, that's a match for the whole string. If none of the characters match then it'll remain 0 regardless.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

which says 'main' must return 'int'.

So return int instead of void. Seriously, use some common sense; these errors aren't exactly being cryptic. I'd explain why void main is wrong, but if your compiler is rejecting it outright then knowing would only be academic. So if you're interested, just search Google for "void main wrong".

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

The question states that each candle burns completely in one hour. That doesn't mean that after half an hour the candle is half gone. If the candle is wider at the bottom than the top, it could take 20 minutes to burn through half its height and 40 minutes to burn the remainder.

Unfortunately, this kind of overthinking is detrimental to finding an answer. Rather than approach it from the most complex way possible, you should simplify through reasonable assumptions. That way the problem can be solved in a consistent state and confounding variables may be added as necessary.

This question is actually pretty old, and yes, you're allowed to assume that the candles all burn uniformly from beginning to end.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I'd use a chat feature for non-help related discussions but I doubt I'd use it to help someone except in rare circumstances.

My experience with the IRC channel is that it's mostly random chat with a slightly technical bent (obviously, because we're techies). Sometimes questions were brought up and answered if it wasn't too time consuming and didn't require detailed examples such as code. For the complex questions or ones where an answer would take more than a couple of sentences, they were directed to the forums. However, often questions encouraged a tangent of discussion that kept things moving.

By far the most entertaining instances of IRC chatting was when crazies from the forum (cough TkTkorrovi cough) came in to rant and we egged them on for lulz. ;)

Reverend Jim commented: Hi-tech fishing :-P +0
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

so what should i do about line 10

Fix line 8.

but at line 102 it is saying 102 C++ forbids comparison between pointer and integer..

That's basically the same thing I said. i is an int and numemps is an array. You can't compare the two because it's not meaningful. Change numemps to an int just like in print_unluckies(); you clearly know how it's supposed to work because you've done it correctly in another function.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

This is my new code but when I cout it tells me the array is uninitialized.

Yes, that's correct. It's harder to see because your indentation is atrociously inconsistent, but the effect is like this:

{
    int odd[15];
}

cout<< odd[3] <<endl;

odd is declared within the braces, and thus its visibility is limited to code within the braces. Therefire, the cout statement doesn't recognize that odd exists. You probably want to declare both odd and even outside of the loop so that they're not reset after each iteration.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Line 10: Often if the line itself is fine, look at previous lines. In this case you neglected to terminate the previous function prototype with a semicolon. The error wasn't detected until line 10, where it caused the compiler to puke.

Line 102: numemps is an array, but you compare it with an int. The two types are not compatible.

Line 115: i was never declared. Line 115 should look exactly like line 102. The error from line 102 won't occur because in this function, numemps is just an int and not an array.