deceptikon 1,790 Code Sniper Team Colleague Featured Poster

It sounds more like the issue is with creating a Windows Service. It's pretty straightforward as far as setting things up, though there are a huge number of variations depending on what you want to do and how you want to do it.

The MSDN tutorial is a good start.

The problem here is that you're asking for things that involve too much code to comfortably put in a post.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I have implemented OpenPOP methodology however it is developed in windows forms and I thought of some windows service to achieve this.

OpenPOP doesn't depend on Windows Forms, last I recall. There may be a Windows Forms test or utility, or something, but you should be able to ignroe it. You can use it in a class library or a Windows Service with no issues at all. Of this I'm sure, because I've done it before.

I used OpenPOP in a service before I moved to my own POP3 management library. And the only reason I moved to my own was to facilitate easier support of IMAP, OWA, and MAPI.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I mean "OOP" is vague.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

i think it's basics of OOPL too

And therein lies the problem. There's not a single "official" definition of what features a language must have to call it object oriented.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

How soon sill they get around teaching with 2013 compilers that have dropped gets()??

Probably never. Why update your curriculum when you can install Virtual Box and simulate DOS to support an ancient compiler that conforms to the 30 year old curriculum? :rolleyes:

rubberman commented: Indeed! It is time to kill that dinosaur! +12
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I don't recall of the top of my head what the polling interval is for sending those emails. Now that we know you're watching this thread, give it 24 hours and let us know if you still don't get an email.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Is the thread in your watched articles list?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Hop into your edit profile page and make sure that "automatically watch articles I post in" is checked. If it is, look for that thread in your watched articles page. I'd wager that you're simply not watching the article, so you won't get new post notifications.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Imperative, procedural, declarative, functional, object-oriented...there are many programming paradigms. C++ is largely imperative (inherited from C), supports OOP, and has been introducing functional aspects lately.

Try looking at Wikipedia for "programming paradigm".

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Hopefully I shouldn't need to explain what gets is or why it's easily one of the worst possible standard functions you could call in your code. In my personal opinion, the title for "holy shit, never use this function" is a tie between gets and system. I'll discuss the problem with system in another article.

The good news is that gets is no longer a problem, provided you use the latest C11 standard. In the 1999 revision of the C language, gets was declared to be deprecated. This means that it was still supported, compilers still had to implement it correctly, but the even as soon as the next minor revision of the standard the function could be removed entirely. And hey, that's exactly what happened. The 2011 revision of C eliminated gets; it's no longer required to be supported, and any use of it makes your code non-portable. Rejoice!

Wait, why does this qualify as a tribal knowledge article? A quick Google search will tell you all you need to know. And while using Google to do research itself may qualify as tribal knowledge (*heavy sarcasm*), I'd hope it wouldn't be necessary to explain to most of you. ;)

No, this article will focus on what to do now that you no longer have guaranteed access to gets. The answer isn't quite as simple as "use fgets" because fgets has quirks too. Rather, let's look at a couple of hand rolled solutions that provide close to the same interface …

mike_2000_17 commented: Another insightful article! Thanks! +14
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Chr(e.KeyCode) always returns capital letters

Yes, because the KeyCode property doesn't include shift state. There's also a Shift property for KeyEventArgs that tells you whether the shift key was pressed (and Alt, and Ctrl). You might consider whether the KeyData or KeyValue properties suit your needs better.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

The answer is the same as when you asked last year. The organization of forums are an artifact of history, and Dani hasn't applied many changes to it in favor of the tagging system.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Is that the ultimate goal? Because if it is you can take a much smaller sample of the numbers and then extrapolate an estimated search time as if the list contained billions of numbers.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

elapsed is declared as a time_point, not a duration. Read up on the chrono library here to see what options are available to you.

The code will compile like this (one of many possible variations):

#include <iostream>
#include <chrono>

using namespace std;

int main()
{
    auto start = chrono::high_resolution_clock::now();
    auto end = chrono::high_resolution_clock::now();
    int interval = 50000000;

    while ((end - start).count() <= interval)
    {
        end = chrono::high_resolution_clock::now();
    }

    cin.get;
}
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Lowest bidder.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

someone correct me these: 1s=1000ms?

Yup.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

mingw32... but i think that it's the GNU too

MinGW's implementation may not use the highest resolution implementation. You might try Boost.Chrono. IIRC, it uses QueryPerformanceCounter under the hood, which is the best you can get in terms of granularity. However, note that on Windows you can't reliably get a higher resolution than 1μs in certain increasingly common circumstances (eg. multicore processors). But it should be sufficient for your current needs.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

The smallest I can think of that doesn't enter the realm of IOCCC and actually opens a form is:

using System.Windows.Forms;

static class Program
{
    static void Main()
    {
        Application.Run(new Form());
    }
}

The bare minimum for a more realistic production quality application in my opinion would be:

using System;
using System.Windows.Forms;

static class Program
{
    [STAThread]
    static void Main()
    {
        AppDomain.CurrentDomain.UnhandledException += (sender, e) =>
        {
            MessageBox.Show("Load Error: " + e.ExceptionObject.ToString());
            MessageBox.Show("An error was detected at load time", "Load Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

            if (Application.MessageLoop)
            {
                Application.Exit();
            }
            else
            {
                Environment.Exit(-1);
            }
        };

        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        Application.Run(new Form());
    }
}

While you typically don't want to do anything that results in an unhandled exception (throwing from a form constructor or event handler, for instance), it does happen occasionally. So adding provisions in there to properly notify and exit even if the message loop hasn't started is an excellent idea.

ddanbe commented: awesome +15
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

*nix is a colloquialism to describe POSIX-based operating systems such as Unix or Linux.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

If that's the goal, you might consider simply removing all commas from the string rather than trying to parse and validate it as a double. Then you can use strtod to do the validation and conversion.

kay19 commented: For helping/tips +2
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Sounds like you just want to pad to 2 digits with 0 as the pad character:

cout << setw(2) << setfill('0') << hour
     << ':'
     << setw(2) << setfill('0') << minute;
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Do I have to create additional for loops statements for each digits and check for comma's/decimal?

If you want to do it manually, yes. However, input streams already support this feature by imbuing the stream with a locale that can recognize a thousands separator. The default "C" locale won't, but if you use the current locale (represented by a name with an empty string), you can read numbers using your system's locale settings:

#include <iostream>
#include <locale>
#include <sstream>
#include <stdexcept>
#include <string>
#include <typeinfo>

using namespace std;

template <typename T>
T parse_formatted(const string& s, locale loc)
{
    stringstream parser(s);
    T result;

    // Set input formatting to the specified locale
    parser.imbue(loc);

    // Attempt to extract a value
    if (!(parser >> result)) {
        throw std::invalid_argument("Unrecognized format for " + string(typeid(T).name()));
    }

    return result;
}

int main() try
{
    string line;

    if (getline(cin, line)) {
        // Parse values using the current system locale
        double value = parse_formatted<double>(line, locale(""));

        cout << "Raw: " << fixed << value << '\n';
    }
}
catch (std::exception& ex) {
    cerr << ex.what() << '\n';
}
Begginnerdev commented: Nice example +9
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Keep sharing these type of things.

I have a bunch of things like this that are hard earned through experience. I was thinking either a series of posts or tutorials each covering one specific topic in detail where the topic is the kind of thing you'd typically learn through painful experience or from talking to experienced programmers.

nitin1 commented: please share those things. excited to know those things +3
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Should I loop through tiles and delete each one? Or is there a better way?

Yes, and. :) With your current setup, you have little choice but to loop through the vector and delete each pointer. However, a better setup would be to use smart pointers (shared_ptr or unique_ptr) from the get go.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Here's an example that may help. Note that it's not a complete solution to your problem, just a similar example:

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

int draw_card()
{
    return 1 + rand() % 100; // [1,100]
}

int main(void)
{
    int wins = 0, losses = 0;

    srand((unsigned)time(NULL));

    // Game loop: plays infinite rounds of HiLo
    while (1) {
        int card = draw_card();
        int guess;

        fputs("High(1) or Low(2)? ", stdout);
        fflush(stdout);

        // Get a sanitized guess
        while (scanf(" %d", &guess) != 1 || (guess != 1 && guess != 2)) {
            puts("Invalid option");
        }

        // Clear extraneous characters from the stream
        while (getchar() != '\n');

        // Check the guess, notify, and update stats
        if (guess == 1) {
            if (card >= draw_card()) {
                puts("You win!");
                ++wins;
            }
            else {
                puts("You lose");
                ++losses;
            }
        }
        else {
            if (card < draw_card()) {
                puts("You win!");
                ++wins;
            }
            else {
                puts("You lose");
                ++losses;
            }
        }

        // Give the user the option to quit
        fputs("Play another round? (y/n): ", stdout);
        fflush(stdout);

        if (tolower(getchar()) != 'y') {
            break;
        }
    }

    printf("Final Score: wins(%d) losses(%d)\n", wins, losses);

    return 0;
}
Pashan commented: you are awesome! +0
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

A common task in C or C++ is to get a string from somewhere and convert it to an integer. "Use atoi" is a common suggestion from the unwashed masses, and on the surface it works like a charm:

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

long long square(int value)
{
    return value * value;
}

long long cube(int value)
{
    return value * square(value);
}

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

    fputs("Enter an integer: ", stdout);
    fflush(stdout);

    if (fgets(buf, sizeof buf, stdin) != NULL) {
        int value = atoi(buf);

        printf("%d\t%lld\t%lld\n", value, square(value), cube(value));
    }

    return 0;
}

"So what's the problem?", you might ask. The problem is that this code is subtly broken. atoi makes two very big assumptions indeed:

  1. The string represents an integer.
  2. The integer can fit in an int.

If the string does not represent an integer at all, atoi will return 0. Yes, that's right. If atoi cannot perform a conversion, it will return a valid result. Which means that if atoi ever returns 0, you have no idea whether it was because the string is actually "0", or the string was invalid. That's about as robust as a library can get...not!

If the string does represent an integer but the integer fails to fit in the range of int, atoi silently invokes undefined behavior. No warning, no error, no recovery. Do not collect $200 and go straight to jail, your program is completely undefined from that point forward.

By the way, don't expect any support …

Ancient Dragon commented: excellent +14
nitin1 commented: hey! you and your way of explaining things is out of the world. excellent!! +3
ddanbe commented: Deep knowledge! +15
mike_2000_17 commented: Interesting! +14
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Read long integers as strings and store the digits of the number in the vector in reverse order.

Then straight C++ won't be enough. The 32-bit limit on long and even 64-bit limit on long long may not be sufficient to store the final value. You need something like GMP or Boost.Multiprecision to extend that limit indefinitely.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Flute.

nitin1 commented: you have told me long time back :D +0
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

when is a destructor of a class called?

When the object goes out of scope or a pointer to the object is deleted.

I'm assuming that when I pop a vector, that will make the pointer no longer valid, is this where the destructor gets called?

Yes, assuming that the object stored in the vector is an object and not a pointer to an object that was dynamically allocated. If you use new or new[], the onus is on you to call delete at the right time.

It's hard to say why your code is locking up without seeing a relevant skeleton.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

There's nothing stopping operator[] from throwing an exception, but I'd be a bit surprised if an implementation does so outside of debug mode. C++'s design model has been that you don't pay for what you don't use, and operator[] has traditionally been an unchecked operation. That's why the at member function was added, to provide a checked operation without forcing people to always pay for the possibility of a throw.

As such, you cannot depend on operator[] throwing. You can depend on at throwing.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

At that granularity, everything is efficient. However, tricks for swapping without a temporary variable have a higher chance of not being as efficient due to potentially confusing the compiler's optimizer.

The lesson to be learned is that it's not worth trying to optimize a few bytes from a single scalar object. You'll get far better returns on the investment of reducing memory usage from large aggregates or optimizing algorithms with a larger impact on performance.

Also, it's rare when you can achieve both space and speed savings; most of the time you can only get one at the cost of the other.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

The code will compile, but the subscript operator for std::vector does not throw an exception. To get an out of range exception you must use the at member function.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

You can get a list of processes and parse the result, but it's highly OS dependent.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I'd use a tuple for heterogenous and/or fixed aggregates. Otherwise I'd use a list. Of course, there are always exceptions, but that's a generally universal guideline.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I understand that's not your point, but please understand that your question is impossible to answer without inside knowledge. We can only speculate.

What I can do is observe that the question presumes financial support for infant formula is truly needed. That may very well be the case, but it might also be the case that a doctor didn't try to ascertain the underlying issue and simply prescribed formula as a band-aid. In that case, the proper solution is not to assist in purchasing formula, but to assist in medical expenses for fixing the real problem.

My purpose in pointing that out is to reach a logical rationale about why related programs could have been shut down.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

In that case I'd question why the baby won't latch. Something is wrong if the natural process of nurturing isn't working. Then again, I'm a problem solver and not a doctor. In my experience, doctors have a tendency to treat symptoms without digging deeper to correct the root cause.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I'm curious, what's wrong with breast milk? Completely free, and arguably healthier in the long term.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

So I would assume that by looking at the stream data (in its encoded form) there may or may not be a way of telling what kind of filter to apply to it in order to decode it.

I don't doubt it, but that may be excessively difficult. You're in luck though, as many file formats will have an identifying prefix in the byte stream that you can use. For example:

Zip:     50 4B
Rar:     52 61 72 21
Tar-LZW: 1F 9D
GZip:    1F 8B
DEFLATE: 78 9C
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I may rewrite a number of my tutorials and close down my site if Daniweb's interface is suitable for...shall we say, somewhat longer tuts with plenty of awesome code? ;) I don't think I've seen any really long ones yet.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Yes, someone can assist. But nobody will do it for you. Please point out what difficulties you're having so that it doesn't sound like you want your homework done for you.

Begginnerdev commented: Sounds like Copy/Paste strikes again! +9
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

It'll compile if you're lucky (probably not though), and you won't get past linking because the underlying library is missing. To make it more obvious what will happen, consider downloading windows.h onto a Linux machine and imagine how far you'd get.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Like when u say "conio.h is not supported", so compiler doesn't support ? How can it be ?

The compiler must implement certain libraries as specified in the ISO standard, these include stdio, stdlib, string, and ctype. Any other libraries are not required, and the compiler vendor can choose not to implement them. The conio library is one such non-standard library, so not all compilers will implement it.

Headers are merely the "public interface" for a library.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

1 - why they want const be uppercase?

It's a naming convention that makes such constants stand out.

2 - why some people adive me use '{' after function\class name and not in next line?

It's just a programming style and makes no difference as long as you're consistent with it. Pick the one you like if you aren't already required to match company or project style guidelines.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

why the 'PRO's' want avoid the "\n"?

It's the opposite. You should avoid endl unless you know that the stream needs to be flushed afterward. Otherwise you should prefer '\n'. endl is implemented like this:

inline ostream& endl(ostream& out)
{
    out.put(out.widen('\n'));
    out.flush();
    return out;
}

There's always an implicit flush involved even if it's not needed.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Start from the simplest and work your way up: RLE, sliding window, LZW, and Huffman are the simpler algorithms. They're relatively easy to implement and reason about.

Production level algorithms tend to be either proprietary or variations/combinations of the simpler ones. Also keep in mind that different types of data compress differently and different algorithms will be optimal. For example, RLE variants are simple, but a solid winner in compression quality when you have text or binary that contains long spans of repeated values.

I'd probably browse Amazon for algorithm books and books specializing on compression algorithms and search Google for specific algorithms as a starting point. Wikipedia will give you a list of algorithms to do further reserach on.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I think WYSIWYG is ideal for the display aspects of web development (HTML and CSS, specifically), and in the next 10 years the tools will hopefully be good enough that we don't need to drop down to the code to do what we want. As it is, drag-drop-configure gets you close, but not quite all the way, and I find myself dropping down to code views to tweak things.

All of the back-end and custom scripting probably won't be replaced with visual designers any time soon.

RikTelner commented: Agreed. +2
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

1 - why some C++ PRO don't advice me use these code?(making properties)

Because it's awkward (as you've discovered), unnecessary, and a complete solution isn't as good as what you'd get with another language like C#. C++ "pros" do without excessively awkward fluff.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

My question is how does the first example work since i haven't used the .Dispose() method

How would that stop the code from working? You've merely failed to release resources, which depending on the resource involved may or may not cause issues down the line.

I m just unsure sometimes when to use using when not.

If a class implements IDisposable, you should either use a using statement, or call the Dispose method when you're done with the object. I include both options even though using should be preferred because there are situations where a using is awkward, and rolling everything up into a try..finally is cleaner.

castajiz_2 commented: ok, tnx +2
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Im trying to accomplish to save both aco####s and settings into the same xml like so

Then if you want to continue using XmlSerializer, you should wrap those two classes in a another class, then serialize that one:

class AppSettings
{
    public General GeneralSettings { get; set; }
    public List<Account> Accounts { get; set; }
}

XmlSerializer treats the entire class hierarchy as a single self-contained XML entity, which means the highest level class is your XML root.

iFrolox commented: Oh, thank you! +2
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

The headers themselves don't do anything, they just provide declarations so that code will compile. You also need the underlying libraries, which if they aren't already provided by the implementation, most likely won't transfer easily.

Your best approach would be to determine which functions you're using and then look for alternatives on the new implementation.