deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I'd wager most of our article level scripting will fail to work, given the suspected cause of the problem. It should be a quick fix, but we need to wait for Dani as she's the gatekeeper for the production server. ;)

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I'm unable to update our production server, so at the very least we'll need to wait until Dani wakes up. But it looks like there was test code in recent changes that fell through the cracks and needs to be rolled back. It should be a quick fix if that's the problem.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I see a possible issue in recent code changes, but until Dani wakes up we can't confirm it or update production. Just sit tight for maybe another hour and things should be resolved.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Microsoft has implemented almost everything in the standard.

Aroo?

I'd say they've implemented almost everything "easy" in the standard, plus partial concurrency. Variadic templates, constexpr, defaulted/deleted functions, and initializer lists are glaring pain points in VC11 that GCC has. The library is thankfully full featured in VC11, relative to the core language, but that's because they've hacked workarounds in to deal with missing features.

Barring concurrency (admittedly a big deal), GCC is further along in terms of core language support. The library doesn't seem to be up to par though.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

this means the function will exept a pointer and it is a IntPtr type.can you tell me how it is equivalent to a double pointer ???

IntPtr is defined as

typedef int* IntPtr;

The second asterisk is hidden by the typedef, so IntPtr* becomes int** when evaluated. Your confusion on the matter is precisely why I generally recommend against hiding levels of indirection with a typedef.

tux4life commented: Agree. +13
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

You can get a list of exported functions (the name specifically), but not the full signature; that information is lost during compilation.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

ITS GIVING ME ERROR AS error: too few arguments to function ‘strnlen’

strnlen()
strlen()

Small but significant differences.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

according to you, contests don't improve a person ?

I didn't say that. But contests do require a unique skillset that isn't directly applicable to the real world, in my opinion. You can derive several skills for real world projects from the skills learned doing contests, but if you treat real projects like a contest I can guarantee you'll find yourself fired in short order. Conversely, the practical techniques used in the real world will consistently fail to do well in any kind of contest.

And more specifically, because I'm sure you'll ask the same question again: my immediate supervisor was a regular winner of programming contests in his college years, and he definitely thinks they were a valuable experience. So yes, doing contests is good for you, but don't trick yourself into thinking that just doing contests will make you a good professional programmer.

nitin1 commented: awesome explaination! can't get this wording from anybody who is in contact of me :-) +2
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Pick any language you're comfortable with. I assume because this thread is in VB.NET that you want to use VB.NET, and that's a perfectly suitable choice. Seriously dude, if you need confirmation from someone else that every little decision you make is okay, this project will take you approximately forever plus one day.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

so deceptikon its that i should bring the barcodes from outside that is not through coding and just do coding of the inventory....u are saying like this no....?

Yes, that's roughly what I was saying.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Didn't work until I prefaced it with http:// .

You'll notice I took care to say the full URL. ;)

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Can you post a super simple test program that exhibits the problem? Just set an int64_t value and write it to file, then post up that program so others can attempt to reproduce the issue.

Also, what compiler and OS? :)

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

but in which language coding is to be done....?

It's too early to pick the language because you don't seem to have a clear idea of what the project is supposed to accomplish. So far all you appear to understand is that you want barcodes and VB.NET; there's no rationale for introducing barcodes in your store or what they might be used for.

Might I suggest coming up with a few use cases for what happens from start to finish on the retail end? Forget about implementation for now, just see if you can nail down a few requirements beyond "I wanna have barcodes!".

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Or you can just type the full URL and we'll linkify it automagically as can be seen in the OP of this thread. :D

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

There's nothing wrong with your usage of INPUT::mi, and Visual Studio compiles it just fine (barring an unrelated warning about a narrowing conversion). What OS are you using? If it's Windows 2000 or later (highly likely) then perhaps there's a setting in NetBeans that's restricting features of the Win32 API. I'm just speculating though, as I'm not familiar with using NetBeans as an IDE/compiler. Maybe someone else can weigh in on it.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I think getting more into it would just confuse you further. Const correctness can be tricky, so it's probably best to just accept this example as an exception to the rule, handle errors as they arise, and wait for a little more experience to faciliate that "aha!" moment.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Constness of a member function only applies to the direct state of the object for its class, so it's completely irrelevant if the non-const hello calls a member function that changes its own state and not the state of hi. It would be different altogether if you tried to change where hello points because that's hi's direct state. It would also be different if hello itself were const, because Test() isn't const qualified. Finally, it would be different if hello were not a pointer because then the state of hello would be a subset of hi's state.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

We won't help you cheat, but we'll be happy to help you write your own program by answering any specific questions you have. Please read our rules.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

You can use negative values in the Add*() methods to represent subtraction from the current value:

datetime.AddSeconds(-1) ' Decrement by one second
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

At last it is even a project and a software for my retail shop..so it will be tough to develop this.... or not...?

Not especially, but I'd strongly recommend doing the school project with an eye toward production but no intention to actually use it as a primary system in your store.

As far as just printing and reading a barcode, adam_k covered the basics nicely. For a real world store you're unlikely to use code 39 (you can download a free font here) unless you're selling something like homemade crafts or the barcode is used for purposes other than inventory management. Retailers selling products created by manufacturers will rely on UPC/EAN barcodes, which is a different symbology from code 39.

The problem with UPC/EAN is that you don't control the barcode values, those are partially selected by the manufacturer and partially assigned by a governing body. Your software must conform to these standards to consume barcodes on products you sell. Further, if you want a UPC/EAN barcode on product that you manufacture, you'd need to register with GS1 to get a unique company code.

That's assuming that you're not generating your own barcodes for internal usage that would ultimately link to the UPC/EAN product in your database. Some retailers do this, but it introduces a not insignificant amount of work in inventorying and preparing product by generating barcodes, putting them in the database, printing stickers, and applying them. I've …

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I'm guessing you want a form that runs before the main form, but you still want to defer the application thread to the main forum? There are a few ways to do that; one of the simpler ones can be seen in a service configuration utility I wrote that looks something like this:

[STAThread]
public static void Main(string[] args) {
    RunApplication(args);
}

private static void RunApplication(string[] args) {
    Trace.AutoFlush = true;
    Trace.Listeners.Add(new TextWriterTraceListener(TraceFile, "Listener_" + ProductShortName + ".Config"));

    Application.EnableVisualStyles();
    Application.SetCompatibleTextRenderingDefault(false);

    AppDomain.CurrentDomain.UnhandledException += (object sender, UnhandledExceptionEventArgs e) => {
        string msg = (e.ExceptionObject as Exception).ToString();
        string logMsg = "Fatal Error: Unhandled exception [" + msg + "]";
        string usrMsg = "An error was detected at load time. Refer to the trace log for details";

        Logger.TraceError(logMsg);
        Utility.FatalBox(usrMsg);

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

    var form = new ServiceConfig();

    if (!form.Login()) {
        Utility.FatalBox("Login failed.");
    } else {
        Application.Run(form);
    }
}

The main form is ServiceConfig, and it has a method that opens a modal dialog for logging in to an external application. All of this is done before the Application.Run(), so the login dialog appears first and if it fails or is canceled the main form won't show.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Your question doesn't make much sense to me. Both versions would be configured to point to a database, so you could easily tell the new version to point to an existing database. The only problems that might arise are changes in the database schema in the new version. In that case you have no choice but to create a new database and migrate data over from the old one. But that's a natural part of destructive upgrades anyway.

It seems almost like your database is tied far too closely to a specific version of the project somehow, though I can't imagine how.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

can you say some thing about it....

Oh the things I can say about it. I've written production software for this exact problem before. ;)

Anyway, is this a real application? Like are you actually going to implement it in a retail store in the real world? Or is this more of an exercise or school project? Because if it's real then you'd be so much better off using existing software and hardware to get the job done:

  1. A barcode sticker printer
  2. Barcode generator software for the printer.
  3. Handheld barcode readers and/or in-counter readers for checkout.
  4. Retail software for inventory lookup.

The barcode part stops after it's scanned because the result will be an inventory item number or UPC/EAN number (most likely the latter). That number is sent to the retail software for lookup and inventory management.

Writing your own VB.NET application to do this would be prohibitively expensive both in terms of development cost and maintenance (not to mention problems caused by bugs and whatnot) compared to the relatively minor cost of purchasing software that already does what you want.

If it's a project that won't be used in the real world then it's much easier to simulate a retail store and its barcoded inventory system.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

What kind of barcode? Are you working with an image or text? Are you actually creating a barcode or reading one? Your question is incredibly vague.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

how compute the average of 6 numbers in an array by assembly language ???

Loop over the numbers and add them up, then divide the sum by 6. You've read our rules, right? I'm not going to do your homework for you, and you've shown no proof of effort to justify being offered any examples.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

main part is how we sort it so as get the bext complexity possible.

You still don't have the best complexity possible. I find it somewhat amusing that you describe your solution as "easiest" and "poor", then complain about the performance of simpler solutions after practically demanding that someone else prove they can solve the same problem. :rolleyes:

for all contests, this approach is much.

Contests require an unreasonable focus on performance. If you want responses that fit into that niche area then make it very clear that your goal is to win contents and not solve a realistic problem.

using bubble sort will give time limit exceeded

Clearly you didn't read the comments that I so carefully included in the code.

nitin1 commented: you are awesome, you are strict and you also teach well. :-D thanks a lot to you +2
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Please ask a specific question.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

And i will suggest to use switch case statement for more fast functioning . .

Potential for "more fast functioning". Switch statements are generally implemented as a lookup table, but there are possible degenerate cases that can affect performance and the suitability of a switch over an if chain:

  1. If the cases are far apart, such as this:

    switch (foo) {
        case 0:   do_something();      break;
        case 100: do_something_else(); break;
    }
    

    Then the switch is far more likely to be generated internally as an if chain:

    if (foo == 0)
        do_something();
    else if (foo == 100)
        do_something_else();
    

    The reason is that generating a lookup table with a large number of unused indices is wasteful as well as potentially slower in terms of cache misses.

  2. A switch is unsuitable for range-based comparisons. If you need to do something like converting a numeric point value into letter grades, if chains are superior in terms of readability:

    if (grade >= 90)
        return 'A';
    else if (80 <= grade && grade <= 89)
        return 'B';
    else if (70 <= grade && grade <= 79)
        return 'C';
    else if (65 <= grade && grade <= 69)
        return 'D';
    else
        return 'F';
    
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

and i wonder if you can do it. :-)

For a "poor man's" suffix array, I can do it easily:

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

static size_t *generate_suffix_array(const char *src)
{
    size_t len = strlen(src);
    size_t *sa = (size_t*)malloc(len * sizeof *sa);

    if (sa) {
        /* Generate unsorted suffix indexes */
        for (size_t i = 0; i < len; ++i)
            sa[i] = i;

        /*
            Note: Bubble sort is used for simplicity. If the string is expected
            to be larger than a few hundred characters it would be a good idea
            to replace this algorithm with something faster.  -deceptikon
        */
        /* Sort the suffix array */
        for (size_t i = 0; i < len; ++i) {
            for (size_t j = len - 1; j > 0; --j) {
                /* Compare in terms of the substring at the suffix index */
                if (strcmp(&src[sa[j]], &src[sa[j - 1]]) < 0) {
                    /* Swap in terms of the index */
                    size_t temp = sa[j];
                    sa[j] = sa[j - 1];
                    sa[j - 1] = temp;
                }
            }
        }
    }

    return sa;
}

int main(void)
{
    const char *src = "abracadabra";
    size_t *sa = generate_suffix_array(src);

    if (!sa) {
        fputs("Error generating suffix array\n", stderr);
        return EXIT_FAILURE;
    }

    fputs("Text:\t", stdout);

    for (size_t i = 0; src[i]; ++i)
        printf("%3c", src[i]);

    fputs("\nIndex\t", stdout);

    for (size_t i = 0; src[i]; ++i)
        printf("%3d", i);

    puts("\n\nPre-sorting\nIndex\tSuffix");

    for (size_t i = 0; src[i]; ++i)
        printf("%d:\t'%s'\n", i, &src[i]);

    puts("\n\nProst-sorting\nIndex\tSuffix");

    for (size_t i = 0; src[i]; ++i)
        printf("%d:\t'%s'\n", sa[i], &src[sa[i]]);

    free(sa);

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

Why are you including the header file "stdafx.h"? I'm not familiar with this in C.

It's a Microsoftism. stdafx.h is a precompiled header that contains all of the libraries and stable headers so that you don't have to include other headers, but primarily to speed up the build process.

What about "stddef.h". Why do you need this?

stddef.h is where ptrdiff_t is defined. You'll see ptrdiff_t used in four_words().

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Can anyone please tell me if there are any other brands of microprocessors, demo-boards, or IDEs that allow programming in assembly?

Um...all of them?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

i dont want any more negative votes to my code.

Your snippet has only one vote. Did you post the code to help others or did you post the code to get an ego boost? Seriously, if you're afraid of negative feedback then you shouldn't put your stuff up for public display. On the other hand, if you're interested in improving yourself then negative feedback is by far the most productive, even if it cuts your ego down to size.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I am not interested to start a war or build tension, so no names - but it does happen.

No doubt that it happens. But my point was that it doesn't happen often enough such that one person will have a high number of solved threads when they didn't actually participate in any significant way.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

It flat won't work (compile errors) because they can't be concantinated like that.

The left operand is a string literal and the right operand is a character literal. It will most certainly compile and run, because the character literal will be interpreted in integer context. Assuming ASCII for the sake of the example, the compiler will see "abc" + 100, which I'm sure you'll agree is both legal and highly error prone. While the address &"abc"[100] can be calculated, any attempt to access it will invoke undefined behavior.

If the right operator were also a string then it wouldn't compile because you'd be adding two pointers, which is not legal. I'm assuming that you just misread the question and saw both operands as string literals. ;)

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

what magic exactly const is doing in the second case ?

I think a better question is how would having a non-const reference to a literal value work? A non-const reference basically says "I'm referring to an object with an address whose value can be modified". A literal value is neither of those: it doesn't exist as an object with an address, nor can it be modified. Therefore it makes sense that referencing a literal with a non-const reference is illegal.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I Just wanna know what happens if we try to do the following in C++: "abc"+'d'

In that particular case, you'd overrun the "abc" array by indexing it beyond the null character at the end. However, whether this is a problem or not depends on how you use the result.

So what's happening? "abc" is converted to a pointer to the first element. Then 'd' is interpreted as an integer value and added to that pointer. The result is the same as any pointer arithmetic of the form p + n. But because "abc" doesn't have enough characters to handle pointer arithmetic beyond p + 3, and (int)'d' is surely much larger than that, you risk undefined behavior.

This is the test program you should have written:

#include <iostream>

int main()
{
    std::cout<< "abcdefg" + 4 <<'\n';
}
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Not until you elaborate. How are you doing "graphics"?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

It depends on the graphics library you're using.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

No, ios::out mode will truncate the file to 0 bytes. You want to use ios::in | ios::out for update mode. An alternative is this:

  1. Open the original file in read mode
  2. Open a temporary file in write mode
  3. Copy the original file to the temporary file

    • Don't copy deleted records
    • Use updated version of records
    • Insert new records as they come
  4. Delete the original file

  5. Rename the temporary file to match the original file

I think that is easier to get right than updating a single file.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

The file's name won't change, you're just overwriting it with updated information. At least, I'm assuming that's how your design works: you have a single database file containing records.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

If you have to delete an entry, the simplest method conceptually is to rewrite the file in its entirety without the entry in question. For huge files that can be a performance issue, but for a school project you don't need to concern yourself with huge files.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

After doing some research I'm confused about why you would use these instead of normal SQL query.

Separation of the query and data is a primary method of defending against SQL injection attacks. There are other reasons for using prepared statements, but since your concern is security, that's basically it.

falsely suggests that no sanitisation of data is needed - completely ignoring other attacks such as XSS, file inclusions etc.

Only if you don't understand what the point of prepared statements is, but it's a valid point that some people will think that handling injection attacks is enough, or assume that by using a library all other possible attacks are mitigated as well. That's less of an issue with the library than it is an issue with the programmer though. ;)

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I wouldn't recommend using strtok() in this case because it modifies the string by way of inserting null characters at the end of each token. This effectively destroys the string for your purposes, so unless you're working with a copy, it's best to stick with a little bit more manual method:

#include <cstring>
#include <iostream>
#include <string>

size_t find_word(const char *s, const char *word)
{
    size_t len = strlen(word);

    for (const char *p = s; *p; ++p) {
        if (strnicmp(p, word, len) == 0)
            return (size_t)(p - s);
    }

    return (size_t)-1;
}

int main()
{
    std::string line, word;

    std::cout<<"Enter a line of text: ";
    getline(std::cin, line);

    std::cout<<"Enter a word to find: ";
    getline(std::cin, word);

    size_t index = find_word(line.c_str(), word.c_str());

    if (index == (size_t)-1)
        std::cout<<"'"<< word <<"' was not found\n";
    else
        std::cout<<"'"<< word <<"' is at index "<< index << '\n';
}

Note that I didn't do anything to replace since you only asked about finding the index of the word in question. I assume you already have ideas for doing the replacement once you have that index?

Also note that stricmp() and strnicmp() are not standard functions, so a compiler isn't required to implement them. However, since you used stricmp() in your code, I'm assuming your compiler does implement them.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Boss??? You mean Dani??? Lol

I don't work for Daniweb full time; I'm actually a developer in my regular day job too. ;)

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Okay, so did you really use a debugger to step through the code? Because the problem is immediately obvious on the first line of your evaluation: you're processing the expression backward. A quick fix would be to use a temporary stack in the evaluation code instead of post, and that stack would be initialized using post like so:

stack temp;

/* Reverse post into temp */
while (!post.isempty()) {
    post.pop(out);
    temp.push(out);
}

// Begin expression evaluation code
// Use temp from here on out and not post

Also, when pushing the result back onto res, you need to reverse your integer to char conversion, otherwise you'll push the wrong value onto the stack:

res.push(c + '0');
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I came up whit this ,but only finds the number of 4 letter word. I dont know how to print all 4 letter words on the screen.

Normally I'd suggest that you set a pointer to the start of each word as you go, then when the word ends if the letter count is 4, print out the characters starting from that pointer. However, that solution doesn't really fall out of your algorithm, so some changes are needed:

#include <ctype.h>
#include <stddef.h>
#include <stdio.h>

int main()
{
    const char *s = "This is a program that reads a file and all four letter words";
    const char *p = s;

    while (*p) {
        const char *start;
        ptrdiff_t len;

        /* Skip leading whitespace */
        while (*p && isspace(*p))
            ++p;

        start = p; /* Save the start of a word */

        /* Jump over the word */
        while (*p && !isspace(*p))
            ++p;

        /* Get the distance between the two pointers (word length) */
        len = p - start;

        if (len == 4) {
            /* Print characters in the calculated distance */
            printf("%.*s\n", len, start);
        }
    }

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

I can answer just about any question on any subject given its a question with one factual answer :)

What happens after we die? ;)

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

All of the code, please. It's a short enough program, and I'd like to make sure I'm seeing what you're seeing. There have been several changes since your original post where all of the code was listed.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I'm guessing you didn't read any of the stickies, given that one of them addresses your exact problem.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Please post your current code.