deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I've noticed that when generating random numbers they repeat.

It sounds like you want a random shuffle rather than a random selection. The former will give you a randomized ordering of the set such that there are no repeats until the set is exhausted:

// Untested code
var rand = new Random();
var to_eat = from x in fruits
             order by rand.Next()
             select x;

foreach (var fruit in to_eat)
{
    Console.WriteLine("nom nom " + fruit.Name);
}

Random doesn't mean "no number will be repeated", it means the sequence of numbers will be suitably unpredictable.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Example, I started off with console apps, I became comfortable with it.
I then started playing around with forms, the code stayed the same.
Then i created services, the code stayed the same.

If you mean the syntax of C#, then sure. But semantics and design can change considerably. Between a console app and a GUI app, the jump to event-driven behavior can be jarring. From personal experience, the jump from a GUI app to an ASP.NET app is quite jarring due to the stateless nature of a web app.

There's a huge learning curve if you know Windows Forms and move to WPF because the design process changes drastically.

Each technology has its own quirks and best practices.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

My finite brain has no trouble with it: we die, we're gone. It doesn't take much intelligence to realize that the most likely scenario is that this life is all we have. If there's more to it, fine, but Occam's razor applies. The most likely scenario doesn't include some divine amazingness to explain life after death.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Please do your own homework. We'll help you work through specific problems in your code or understanding of the question, but won't do the work for you.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

pointer= new T;

This allocates one instance of T. To create multiples, use the new[] syntax with your size:

pointer = new T[size];

pointer++;

Very bad idea. You shouldn't modify the base pointer unless you're careful to roll it back at some point. This is because it can mess up both indexing and when you delete the pointer (something your class is missing presently).

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Luckily for you, a lot of students try to cheat on these forums by posting their homework assignment. Just look through those to get ideas, but please don't post your solution for the cheaters to turn in.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

How exactly do you want the child anchored? Absolute position? Relative percent?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

"Expert" is a tricky word. I wouldn't expect anyone to be an expert in one of those, much less all of them. However, being competent in all of them or even proficient is certainly possible.

Though Silverlight's lifetime is questionable. We're not sure if Microsoft will continue to expand and maintain it with the advent of HTML5. Windows Forms may have a similar fate.

The current du jour core technologies seem to be Entity Framework, WCF, MVC, WPF, and Azure.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Your issue may be that std::cin >> name; does not remove the newline char from the resulting string.

The >> operator is delimited by whitespace, so it would never store a newline unless you go out of your way to make it happen. The problem is more likely that the names are multiple words, and >> only extracts a single word.

Of course, a more complete piece of code that we can actually run would be helpful in troubleshooting. ;)

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

An interesting, if optimistic, hypothesis.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Code highlighting doesn't run after a post is submitted. If you reload the page, your code will be displayed with highlighting.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Currency. {0:C} says that the first argument after the format string is to be formatted with the standard currency formatter.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Sounds like a good place to use a map:

vector<string> v =
{
    "Jan2013",
    "Jan2013",
    "Jan2013",
    "Jan2014",
    "Jan2014",
    "Jan2014",
    "Jan2014",
    "Feb2014",
    "Feb2014"
};
map<string, int> freq;

// Loop through the vector
for (auto x : v)
{
    ++freq[*x];
}

for (auto x : freq)
{
    cout << "total count for " << x.first << " = " << x.second << '\n';
}
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Also of note is that user controls themselves have overhead in terms of maintenance due to the boilerplate required. It's not much, but enough to give one pause for small projects. For medium to large sized projects, the modularization benefit overwhelms the extra maintenance of more code.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Just the function or member function name won't do, the argument list is required even if it's empty. For example:

obj2->Landline(); // Notice the parentheses

Also note that you'll immediately get a runtime failure because obj2 doesn't point to anything. Either make it a regular object:

PCTL obj2;

...

obj2.Landline();

Or have the pointer point to an object:

PCTL base_obj;
PCTL *obj2 = &base_object;

obj2->Landline();
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

While there might be a tool out there to do the conversion, I wouldn't trust it. The appropriate way is to know both languages and convert manually. However, since assemblies written in either language are interoperable, there's no need to convert unless you're trying to match company standards where only C# is used. And even then, the conversion effort should be minimal unless you're "borrowing" significant chunks of code from somewhere else. ;)

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Thanks for your kind advice and suggestion but may I know why does the error shows

For the same reason you can't say classObjects("foo") == classObjects("bar"). User defined types must explicitly support this syntax through overloaded operators, and find uses that syntax internally.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I'm not too sure about that -- the OP never said which one he/she wants.

I can't divine what the OP wants, but the first post clearly said items: "I was wondering if anyone had suggestions on how to get the number of items in a file, without knowing before hand."

Further, the sample code strongly suggests arbitrary integers from a text file rather than bytes.

But maybe the OP didn't know what he/she wanted.

That's a possibility. We can only go on what was asked, and I'm having difficulty interpreting the OP's question as the number of bytes in a file.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

The thumbnails still take up contiguous memory. Usually when you get an out of memory exception in image processing, it's due to fragmentation. Have you considered using a window of the thumbnails rather than trying to display all of them? That way you have a manageable subset of bitmaps in memory at any given time.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Well if I think for just a second the size of int is possible to obtain by sizeof(int).

True, but how do you know that the sizeof(int) bytes you read really represent an integer value? That works for binary files where the format is known, but for text files you're SOL on that assumption because values are represented by strings of characters rather than their in-memory bit pattern.

If you would like to read the file, you need to open the file, and then if my memory serves me well, y ou automaticly lose the procesor. Now your program is in queue with others, and loses time. There are some files that go with any file, and that are kept on the system, it would be way faster to read those things. Sorry, I don't know how to do it yet.

I'm still not sure what point you're trying to make. In a multitasking OS, this is a given regardless of what you're doing.

And if you work with binary file mode, in the heder of a file there is a infomation how big or small is the file. Try some examples on bmp file, in the struct that is at the begining you could find that thing.

Only if the file format has header information and the header information includes the size.

But, if is possible to get it without opening it, like find the place where system keep that info, and …

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

The default find uses relational operators overloaded by the contained type (operator== to be precise). If you don't have those, you can either add them or use find_if with a predicate that handles a custom comparison.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

So...Windows 8.1 with a proper start menu? Running Metro apps on the desktop seems interesting, but not really a make or break feature. Having the two IE versions talk to each other would be nice. Do these reliable sources have any other information? If not, I'm not seeing much of an improvement aside from placating the whiners. ;)

Granted, the start button in 8.1 is a clear and definite "F You!" from the UI designers.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

ReDim Preserve marks(10) is important to be written here?

Preserve retains existing values in the array, so if you want to keep the values of indexes 0 through 2, it's important.

ReDim marks(2) is important to be written in this way?

Um...yes?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I'd probably go with a simple licensing mechanism:

using System;
using System.Globalization;

namespace BasicLicense
{
    public class License
    {
        public string ProductCode { get; set; }
        public DateTime ExpiresOn { get; set; }
        public bool IsValid { get; set; }

        public License(string licenseCode, string productCode, string registeredTo)
        {
            ExtractLicense(licenseCode, productCode, registeredTo);
        }

        private void ExtractLicense(string licenseCode, string productCode, string registeredTo)
        {
            IsValid = false;

            try
            {
                string licenseData;

                using (var crypto = new Decryption(registeredTo, "ALLPURPOSELICENSE"))
                {
                    licenseData = crypto.Decrypt(licenseCode);
                }

                var parts = licenseData.Split('|');

                // License format: PRODUCT_CODE|EXPIRES_ON|"LIC"
                if (parts.Length == 3 && parts[2] == "LIC")
                {
                    ProductCode = parts[0];
                    ExpiresOn = DateTime.ParseExact(parts[1], "yymmdd", null, DateTimeStyles.None);

                    if (ProductCode == productCode && ExpiresOn >= DateTime.Today)
                    {
                        IsValid = true;
                    }
                }
            }
            catch
            {
                // Ignore the exception, the license is invalid
            }
        }
    }
}

By default the application would be installed with a demo license where the expiration date is set 30 days after the time of installation. Once the trial is converted to a permanent license, the expiration date can be set to DateTime.MaxValue. Easy peasy.

Edit: Whoops, thought this was the C# forum. I'm too lazy to convert the code, but it's relatively simple. ;)

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Just post under Software Development with a tag for Microsoft Dynamics AX. :) Dani wants to move toward more of a tag-based system anyway, so new categories are unlikely.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

This article may be helpful. It describes both recursive traversal and an iterator based design.

But I've no idea how to implement it in the program.

You mean calling the function? Your first example should work, provided fun is defined and t is a pointer to bst_char. Another variation would be this:

char print(char item)
{
    putchar(item);
}

int main(void)
{
    bst_char tree;

    // Build the tree...

    bst_char_iterate(&tree, print);

    // Destroy the tree...

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

The good news is that your choice of database largely doesn't matter if it's compatible with ADO.NET. The Entity Framework has a database factory that will create the appropriate objects for you given a suitable connection string and provider in app.config/web.config. You can just write your code to manage a database, then switch between Access, SQL Server, MySQL, Oracle, etc... by changing a couple of configuration strings.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Since you have free options of SQL Server, I see no reason to rely on Access databases. They're too restricted to be worth it most of the time.

p.s: i hope this was not against the rules "can i trust to Crd version of sql server 2012?

Discussion of cracked software (which is what I assume you mean with "Crd") is against the rules. And the answer to your question is no, you can't trust it.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

But why do some websites insist that my password HAS to have letters AND digits?

Mindless tradition, probably. For the longest time the bare minimum password policy was at least 8 characters including one upper case letter, one lower case letter, one number, and one special character.

These days a pass phrase is more secure due to its length, but many sites still have a character maximum and/or character combination checks that preclude a pass phrase. I can only assume it's because they follow "best practice" without putting any more thought into it.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Because '!' and '}' have to be included in the try set. I'll put it a different way. Why is this loop?

for (int i = 0; i < 27; i++)
{
    for (int j = 0; j < 27; j++)
    {
        // Stuff
    }
}

Faster than this loop?

for (int i = 0; i < 127; i++)
{
    for (int j = 0; j < 127; j++)
    {
        // Stuff
    }
}

The same principle applies. The more you have to consider in what characters might be there, the longer it takes to actually identify them.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Put simply, the larger the character set used, the longer it takes to do a brute force crack of the password. If you just use letters, or even just lower case letters, your string would have to be longer to have the same security as if it used more varied characters.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Sounds like a CAPTCHA failure. You should be able to refresh the images to get something you can easily recognize. CAPTCHAs are used to restrict registration to actual humans and reject bots.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

It's a C library, but also works for C++.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Provided your compiler supports the non-standard conio library, it'll work between C and C++.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

That's an old dialect of C++ and doesn't use any difficult to convert features. You need to do three things:

  1. Change cin to scanf function calls.
  2. Change cout to printf function calls.
  3. Add a typedef to your structure so that the struct keyord isn't required:

    typedef struct mahasiswa
    {
    int nbi;
    char nama[50];
    char alamat[50];
    int telp;
    } mahasiswa;
    

For #3, as an alternative you can add the struct keyword to every declaration of the type:

struct mahasiswa data[3];
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I actually prefer seeing int clocks_per_ms = CLOCKS_PER_SEC / 1000; to int clocks_per_ms = 1000;.

Me too. Too bad CLOCKS_PER_SEC isn't guaranteed to be 1000. ;)

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

How do the indexes relate in those two join tables? Can you show me an example of what the data might look like?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

How exactly is your database structured?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Right now all it does is print out the numbers. I'm not going to write the whole thing for you, so try to finish up that last part. I assure you, it's quite simple. I'll even give you a hint: use three counter variables and increment them appropriately for each number, then print those counters after the loop ends.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

ofstream myfile; // input file

In what way does ofstream represent an input file? Take a look at my basic starting point example and work from there. You're reading a file, not writing one.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I might organize my database so that I could do something like this:

var presentation = from m in db.PresentationModules
                   where m.PresentationId = pid
                   orderby m.ModuleIndex
                   select new
                   {
                       Module = m,
                       Components = from c in db.ModuleComponents
                                    where c.ModuleIndex = m.ModuleIndex
                                    orderby c.ComponentIndex
                   };

That way I could select a collection of modules and module components tied to the user. The collection can then be used in a more convenient manner than diddling around with indexes.

ddanbe commented: Indeed eternally awesome! +14
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

What have you tried so far? And please don't say "I don't know how to start", because that's an extremely lame excuse. Anyone with a passing familiarity with C++ should be able to write this as a starting point:

#include <fstream>
#include <iostream>

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

    if (in)
    {
        int num;

        while (in >> num)
        {
            cout << num << '\n';
        }
    }
}
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I can think of several ways to do this, but more detail would help. What is this algorithm ultimately doing? Describing what you want to accomplish rather than how you want to accomplish it works better when looking for alternative methods.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

The idea of this tutorial is to give people the idea how to write sleep on their own. just as you can be asked to write sort or other function which already exist. its a tutorial not a cheat code.

Nobody is dismissing your code as useless. We're simply highlighting issues that anyone who uses it should be aware of.

Here's a portable version that uses time_t:

void s_sleep(double seconds)
{
    time_t start = time(0);

    while (difftime(time(0), start) <= seconds)
        ;
}

You can certainly pass fractions of a second, but there's no guarantee that the timing will be accurate beyond a whole second. The difference is that instead of directly using arithmetic on time_t, difftime handles the comparison portably.

With clock_t, you can get a slightly better result, but it's not portable. However, in practice it's unlikely to fail (which, it's important to note, is the same with time_t):

void ms_sleep(int milliseconds)
{
    clock_t start = clock();
    int clocks_per_ms = CLOCKS_PER_SEC / 1000;

    while (((double)clock() - start) / clocks_per_ms < milliseconds)
        ;
}

For quick and dirty, one of these would be my go to function.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

You're trying to save a string into an image type, those two are incompatible. You need to extract a byte array of the image to pass to SQL.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

There is no sleep function that is 100% accurate

It really depends on what granularity you're looking for. More precise timing becomes more and more difficult, as you mentioned, for various reasons. However, time_t is only guaranteed to be accurate to the second. clock_t is better, but the granularity varies by implementation.

I'd be vastly more concerned about a busy loop than precision in all but the most extreme of cases.

Ancient Dragon commented: Agree :) +14
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

For a quick and dirty sleep, that's fine (though not strictly portable). But note that a busy loop will consume vast CPU resources whereas a platform provided sleep typically puts the process/thread truly to sleep so that other processes can get a turn. The great differences in how an OS will handle this is why the language hasn't offered such a feature so far.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Please post your web.config file. Feel free to censor user names, server names, and passwords. It looks like the connection string is malformed for the information you've already provided.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Two things:

  1. String literals don't span lines. Provided there's nothing in between, you can make each line a string literal and they will be automatically concatenated onto one:

    fprintf(fp, 
        "char out[8];char cur[8];"
        "char con[255, 255, 255, 255, 255, 255, 255, 255];\n"
        "if cur == con out == 0, 0, 0, 0, 0, 0, 0, 0;\n"
        "while (cur <= con)\n"
        "    con = con - 1\n"
        "if cur >= con out = out + 1;");
    
  2. The "code" in your string is completely malformed and illegal C.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

2014: The usual evening, an inconvenient day off, and now I have to remember to write 2014 instead of 2013.