deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I'm not sure I understand the requirements and they're not obvious from the code given. What should this calculator be doing?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

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

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

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

void clear_line(FILE* in)
{
    int ch;

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

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

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

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

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

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

You still haven't clarified your question.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

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

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Besides the article choice, the editor is possible the worst Ive seen in my life, including old school boards.

The editor and preview are a primary focus for improvement, but it's not going to appeal to everyone. That just goes with the territory. ;) We welcome any and all suggestions for improvements and new features, but if all of your suggestions amount to "let's go back to the old way", you're probably going to be disappointed.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Update: I found it and it's a bug. Stand by for a fix in the near future.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Hmm. Watched article notifications already exclude any articles where the last poster is also the watcher. I'll dig deeper and see if I can find out what's going wrong.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

The default back-end for std::queue is std::deque, which grows and shrinks dynamically. std::queue is actually a form of adapter that sits on top of a data structure to provide a convenient interface. std::stack is the same way.

std::deque is implemented in a somewhat confusing way, so you might consider studying how std::vector works intead (it's basically a dynamic array). It grows dynamically as well, but in a much more intuitive manner. That should get you rolling on answering the question: "how have they created something like that?". :)

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Are these watched thread notifications or recommended thread notifications?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

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

Click here for a solution to your problem.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Do you have a question?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

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

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

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

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

#include <stdio.h>

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

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

    return 0;
}

If you type "gabcxyz" the output will be:

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

If you type "gxyz" the output will be:

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

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

#include <stdio.h>

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

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

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

All errors are resolved and it runs, but as soon as it starts it says "main.exe has stopped working" and closes.

That's what I'd call "doesn't run", given that it crashes immediately upon loading. What you want to do is run your program in a debugger so that execution can be stopped on the offending line of code.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

C++ doesn't do graphical elements. You'll need to use a GUI library of some sort, though upgrading to a compiler that wasn't designed for MS-DOS would greatly facilitate your search for a working library..

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Context_b16187_25845991

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

You can declare a function inside a function via a data structure

True. And because the OP is referencing material based around C++11, it couldn't hurt to mention that lambdas can also be used to create a nested function effect.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

thanks. but how about the in variable before "%s %s". how can you write it in c++?

Whoops, I see you're reading from a file (most likely). You'd need to open an fstream much the same way you open a FILE pointer using fopen():

ifstream in("myfile");

if (in)
{
    ...

    in >> student[x].name >> std::ws >> student[x].num;

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

It's not much different from declaring a function at file scope:

void some_function();

std::thread f()
{
    return std::thread(some_function);
}

The difference between this and your example is the visibility of some_function in the file. When the declaration is at file scope, everything after the declaration in the file can see it. When the declaration is at function scope, it's only visible within that function.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Could you be any more vague? The thing is I made a bet with a coworker that "I have to scan a file for things" isn't the worst possible question one could ask if one is expecting any kind of useful answer.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

In C, you must know what you are doing.

Yes indeed.

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

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

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Exhibit A: CRobot** donut_population;
Exhibit B: init_population(donut_population, pop_alpha, pop_beta)
Exhibit C: void init_population(int** donut_population

The donut_population you pass is CRobot**, but init_population() expects int**.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Um, triumphost...fscanf() is for input, cout is for output. You probably mean cin:

std::cin >> student[x].name >> std::ws >> student[x].num;

Unfortunately, cin doesn't try to match literal data, but literal whitespace in the *scanf() format string is a special case. It means "extract and ignore any amount or type of whitespace". Conveniently enough, the ws modifier works the same way when used with cin.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Does the following not work?

returnSeq.seqType = RNA; /* Initializing to RNA, for example */
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I don't see the benefit here, especially given the hoops you'd have to jump through to achieve the desired syntax. Is it possible? Yes. Is it worth it? Only if you can come up with a justification that amounts to more than saving two keystrokes (the angle brackets in this case). Oh, and new isn't a legal variable name. ;)

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

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

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

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

For any question that starts with "is it possible", the answer is nearly always going to be yes. Yes, it's possible. No, it's not as easy, safe, or robust without more effort and great care on your part.

Since this is starting to seem like homework and you still haven't proven that you've attempted anything, I'll refrain from offering a manual parsing example. Instead, I'll ask for details on your assignment, because you clearly have unreasonable restrictions that cannot be assumed.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I'm assuming you're reading the entire input into a single string. You'll need to first break this string up into individual "words", or items separated by whitespace. Then each word will need to be converted to an integer and assigned to the array.

For example:

#include <iostream>
#include <iterator>
#include <sstream>
#include <string>
#include <vector>

using namespace std;

int main()
{
    vector<int> v;
    string input;

    cout << "Enter a sequence of numbers: ";

    if (getline(cin, input))
    {
        istringstream iss(input);
        string num;

        while (iss >> num)
        {
            istringstream converter(num);
            int x;

            if (converter >> x)
            {
                v.push_back(x);
            }
        }
    }

    copy(v.begin(), v.end(), ostream_iterator<int>(cout, " "));
    cout << endl;
}
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

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

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

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

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

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

using namespace std;

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

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

    cout << displayValue << endl;
}

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

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

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

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

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

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

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

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

The accepted way to terminate your account is to remove any personal information from your edit profile page, log out, and never log back in under that name. Naturally this doesn't actually remove the account (which we retain for anti-spam law conformance) or any of your posts (which we retain for continuity).

If you'd like, I can make these changes for you. Just send me a PM.

And finally, if I may ask, why exactly do you want to delete your account?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

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

some of these people are just plain ungrateful :(

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

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

The problem was the {...} delimiters in the post. It looks like Dani added a code validation rule to account for weaknesses in the editor's highlighting algorithms, and it explicitly disallows braces for some reason. I'm not sure what the reason is, as we've disabled the only place in Markdown that I'm aware of where braces are meaningful.

I'll let Dani weigh in when she wakes up, but that's the reason. :)

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Why would one be permanently linked to a website?

Because we send bulk emails and need to prove that everyone we've sent an email to has opted into it by registering. It's equally effective to remove all personal information from your profile (some of which, such as changing your user name can be accomplished with the help of an admin), unchecking all options that would cause us to automatically send you emails, then never logging in again.

Feel free to PM me with options for a new user name, and I'll be happy to make all of these changes for you.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

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

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Being human that I am (I really, really am!) and having preferences and being overly-opinionated in every possible field, my answer to "What kind of device is IPad?" was "Crappy". Not that I find it crappy, I just generaly dislike mass-produced consumer items, but that doesn't matter.. what matters that I'm too much of a human to remember my password and not enough to pass as one.

It was a trick question. We gave you a question to check if you're human, but the question itself depended on the rationality of a computer. Muahahaha! ;)

But seriously, I don't like that question because there's not a 100% clear answer. While you would expect most people to answer "tablet", that's not the only correct answer. Browsing through the questions, I found another that will surely produce a high instance of wrong answers given the answer list:

What is someone who plays football called?

And being neurotic about it on the programming forums, this one chafes:

How many bits are there in a byte?

FYI, I made a few tweaks that should help a bit, hopefully.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

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

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Include <climits> for PATH_MAX,and MAXPATHLEN is in <sys/param.h>.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster
#include <iostream>

using namespace std;

#define PATTERN   "-"
#define SEPARATOR " "

int main()
{
   int row,col,n;
   cout<<"Enter an Integer number:\n";
   cin>> n;

   cout<<("Numerical Pattern\n");
   for ( row = 1 ; row <=n ; row++ )
   {
       for ( col=1; col <= row ; col++ )
       {
          if(col==row)
          {
             cout<< PATTERN;
          }
          else
          {
             cout<< SEPARATOR;
          }
       }

       cout<<endl;   
   }

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

In other words are there instances where nodes are specifically needed to be sorted.

Yes. Ordering of data is one of the most fundamental tasks. Whether you're using a linked list, an array, or a tree structure, some kind of ordering will be needed in the majority of cases.

Also, why is the string data member of a node in a linked list not destroyed when the node itself is destroyed.

We can't read your code unless you post it, so I'll assume that your list doesn't use RAII-friendly objects like std::string for this "string data member". In such a case, the string memory isn't destroyed because you don't destroy it.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

how does fprintf() get know - when the list of parameters is ended ?

It relies on the format string for this information. That's why nothing bad happens if you provide more arguments than the format string uses, but it's undefined behavior if you provide fewer.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Which barcode symbology are you using?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

There are two versions of iota: an old non-standard version and the standard version added with C++11. I assume you're trying to use the latter, in which case you need to both have a version of GCC that supports that particular part of C++11 and turn on the -std=c++0x switch.

Unfortunately, I don't remember exactly which version of GCC started supporting iota, but it works just peachy in my version (4.6.0).

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Two nitpicks:

  1. We're not talking about return values here, we're talking about parameters and arguments.
  2. A reference is not the same thing as a pointer (though it may be implemented as a pointer under the hood).
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

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

Do the same thing twice:

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

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

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

hey guys there is a problem with the input file and there is too many bugs........

Wow, that's just soooo informative. Can you elaborate about what the problem is?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

In case 1 n is uninitialized, so you're printing whatever random garbage was at that memory location. In case 2 n is initialized, but once again foo() doesn't change it, so the value remains 4. In case 3, fooWithRef() does change the value of n, so you get the new value.

The difference is that foo() makes a copy of the value you pass while fooWithRef() creates an alias to the object. It can help to see that function parameters are not the same thing as the arguments by not naming them the same:

void foo(int value)
{
    value = 6;
}
void fooWithRef(int& alias)
{
    alias = 6;
}

In practice, what's happening is closer to this:

int main()
{
    int n;

    {
        int __temp = n;
        foo(__temp);
    }
    printf("Case_1 Result: %d \n", n);

    n = 4;
    {
        int __temp = n;
        foo(__temp);
    }
    printf("Case_2 Result: %d \n", n);

    {
        int& __temp = n;
        fooWithRef(__temp);
    }
    printf("Case_3 Result: %d", n);
}

So as long as you understand that a reference is an alias for an object and changes to the alias also change the original, while a non-reference doesn't alias the object and only copies the value, the behavior is perfectly reasonable. :)

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

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

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

Does try { } catch make program slower?

No. There's a performance hit to actually throwing an exception, but if you don't catch it, it'll just propagate up and potentially be unhandled. In the case of exceptions you have no control over such as the standard or third party libraries, there's really no option but to catch it somewhere. For exceptions you yourself throw, that's where the guidelines of only throwing an exception where it's truly appropriate come in (because there's a performance cost when you throw). ;)