Narue 5,707 Bad Cop Team Colleague

0
For what it's worth, here's one that's just a few macros:

#include <time.h>
clock_t startm, stopm;
#define START if ( (startm = clock()) == -1) {printf("Error calling clock");exit(1);}
#define STOP if ( (stopm = clock()) == -1) {printf("Error calling clock");exit(1);}
#define PRINTTIME printf( "%6.3f seconds used by the processor.", ((double)stopm-startm)/CLOCKS_PER_SEC);
Then just use it with:

main() {
START;
// Do stuff you want to time
STOP;
PRINTTIME;
}

Not a good use of the preprocessor. Let's look at a few reasons why:

  • Global variables used in macros. Scary.
  • Object macros that have hidden side effects and don't really evaluate to objects or values.
  • Order is important, but neither enforced nor encouraged (try doing PRINTTIME before START or STOP).
  • Failure terminates the whole application!?

Seriously, just put forth a little more effort and write a stopwatch ADT. Macro hell isn't a good place to be.

Narue 5,707 Bad Cop Team Colleague

Dave is one of the few people online I consider a good friend. Daniweb will be far less fun now.

iamthwee commented: The Famous C/C++ trio, Salem, dave and narue is no longer :( [quazh doesn't count ;)) +0
Narue 5,707 Bad Cop Team Colleague

> That being said, we are launching a new design for the site in about a month. I will give it a try at first, not using a modal, and see if all of the activity stats drop off.
So the new design has been up and running without the modal for about 5 days now, and unfortunately I have no other choice than to put it back into play. Registration rates decreased from nearly 1000 new members registering to just under 100 new members registering daily!

However, I did make some major changes to the modal in this new version. Firstly, it loads MUCH, MUCH quicker. Secondly, it now also includes a login box.

How many of those new members actually post? How many post once or twice and then are never heard from again? I'm sure it looks good to have "58308583085839895783957 members!!!!111lolzors" at the top of the page, but if only a couple thousand die hard members are making any real use of Daniweb, that number is meaningless. And of course, alienating the die hard members to make that number grow doesn't seem like a good strategy.

Personally, I haven't have any trouble with the popup, but I have gotten the impression that lately you care more about numbers than the people who drive Daniweb. If those people leave, you'll be left with a lot of crap (spam, cheating students, and general garbage), and Daniweb will become just another fallen forum.

Just sayin'.

Nick Evan commented: I agree, too many "lolzors" are signing up lately +0
Narue 5,707 Bad Cop Team Colleague

implentation of m-ary tree in C

If you understand the concept then an implementation isn't terribly difficult with a little effort on your part. So go do your own homework. We won't bail you out. kthxbye.

any simple example?

No. In my experience, people asking for "simple" examples of something reasonably complex don't understand the simplest example possible and then continue to ask for explanations and excessive hand holding. It's a waste of time to type up the example in the first place, so I don't do it anymore unless you show promise.

Narue 5,707 Bad Cop Team Colleague

Ah, ok, so I'm a little out of my depth. I haven't got to the copy constructor bit in the manual. Thank you so much for the response. Although you've also thrown up something else I don't understand: I don't get why passing objects of the class around by value is a bad idea because I don't know what dynamically allocated means... can you tell me please?

itsX and itsY are pointers, and you allocate memory to those pointers with new . That's what dynamically allocated means. The default copy constructor just does a shallow copy, much like this:

Point(const Point& rhs)
{
    itsX = rhs.itsX;
    itsY = rhs.itsY;
}

But what this does is copy the pointers, not the memory pointed to by the pointers. The end result is you have two objects that refer to the same memory. If one of those objects goes out of scope, the destructor deletes the memory and the other object now references deleted memory.

Typically when you accidentally cause objects to share memory, that's really a bad thing. ;) So you need to use a custom copy constructor which allocates memory and copies data:

Point(const Point& rhs)
{
    itsX = new int(*rhs.itsX);
    itsY = new int(*rhs.itsY);
}

This way the memory is completely owned and managed by each object.

kvprajapati commented: Informative. +9
Narue 5,707 Bad Cop Team Colleague

You don't need an array, this can be done by streaming the numbers to the output file directly using a merge algorithm. The merge algorithm is straightforward, and I'll encourage you to see what you can come up with on your own. However, merging is a common task, so you'll find heaps of examples online. And if you just can't figure it out, come back here and someone will outline it for you.

Narue 5,707 Bad Cop Team Colleague

Its come to my attention that some members of this board do NOT regard the feelings of others as any importance at all when considering a reply.

One doesn't garner respect simply by having a pulse. Respect is earned through proving that one is worthy of respect.

This is contradictory to the point of a forum, a forums purpose is to create an environment conducive to that of being positive.

I think you misunderstand the point of a forum. If the forum is meant for answering technical questions then the purpose is education. Education doesn't always mean giving the requested answer. It often means showing people how to find answers for themselves (ie. "google is your friend") such that running to others for help is no longer needed. Sometimes it means scolding people into more acceptable behavior.

All that is needed is a deep breath of patience and a simple reply of “ please do not post homework assignments for others to do for you :) thank you.”

In my experience that's not enough of a shock to alter behavior. The same person will do the same thing unless you make it clear that such behavior is unacceptable, in a way that hurts as much as possible. Pain is an excellent teacher. Warm and squishy slaps on the hand are not.

Another problem area I have noticed is when someone posts a simple question you may see a response something similar to this “ just google it”, …

Narue 5,707 Bad Cop Team Colleague

There are a million and one ways to parse a string. Here's one idea that might get your creative juices flowing:

while (getline(in, line))
{
    // Skip comments
    if (line[0] == '#')
    {
        continue;
    }

    istringstream split(line);
    string temp;

    while (getline(split, temp, '='))
    {
        int value;

        split>> value;
        cout<< value <<'\n';
    }
}
Ancient Dragon commented: My thoughts too :) +28
Narue 5,707 Bad Cop Team Colleague

Did it not occur to you that you can upgrade to a more modern compiler? You should be aware that C is no longer the same language it was when Turbo C came out. Not to mention compilers in general have improved drastically in the last twenty years.

Narue 5,707 Bad Cop Team Colleague

im not looking for those boring library management,hotel management and stuff but something interseting which will force me to think.

I think you'll find much of the "boring" stuff will indeed force you to think if you do it properly. Any idiot can write an amateurish project without thinking. Writing robust and complete software is much harder than you seem to realize.

so any ideas....

Well, since you're soooo advanced, how about writing an IRC chat client? Maybe a compiler? Or perhaps a MUD? Those are fun. Wait, you said you've done graphics, so someone of your caliber can easily write a graphical MMORPG like World of Warcraft. A nice text editor to replace the blue ugliness of your ancient IDE would be a good project too.

oh and use turbo c++ 3.0 not the ones the dont use <iostream.h> and require 'using namespace std'a and stuff.

You asked for ideas, not code. If what you really want is a freebie tailored to your crap ass compiler, I encourage you to piss off.

tux4life commented: Thread solved :P +8
Narue 5,707 Bad Cop Team Colleague

> I'm not getting the impression that there's a starting point that we can easily work from to get to our desired forums
The homepage?

Worthless. ;) I never used it before and I'm not likely to start. My starting point has always been the forum list. Note that I can't find a link to the forum list even from the homepage. It's almost as if www.daniweb.com/forums is a hidden feature.

To be perfectly honest, when I joined Daniweb it was a forum. Now I'm not sure what it's trying to be, and the forum is simply an afterthought in terms of presentation of the site (such as the homepage).

I'm still not sure if I like the new design or not.

p.s. I noticed that I couldn't toggle plain text on a code listing from the advanced reply editor. I had to copy/paste the highlighted code and remove #'s manually. Minor annoyance.

Narue 5,707 Bad Cop Team Colleague

Site navigation feels clunky now. I'm not sure what use cases you were using to design the site, but it's definitely more tedious to get around, in my opinion. I think it's this feeling of rough navigation that makes the whole site seem "bigger" and "harder to read".

I'm not getting the impression that there's a starting point that we can easily work from to get to our desired forums, and there's no easy way to get back (ex. I can't find a way to get to the main forum list without using my browser's bookmark). The whole "here's where I am, here's where I came from, here's where I want to go, and getting between them is easy" feeling just isn't there anymore.

diafol commented: Agree +0
Narue 5,707 Bad Cop Team Colleague

>It won't work in MSVC
And that didn't raise any red flags for you?

>char* read;
>cin >> read;

Pointers are not magic. If you try to write to an uninitialized pointer you don't get infinite memory, you get undefined behavior and access violations which tend to crash your program.

>int* line = new int[strlen(read)];
Um...I see a fundamental misunderstanding here. Most likely you're not familiar enough with the lower level aspects of C++ to give "tips" adequately. Also note that strlen is declared in <cstring>, which you failed to include.

>for(int i=0; i<strlen(read); i++)
I'm all for not optimizing prematurely, but things like calling strlen every iteration of a loop are best described as "premature pessimization". strlen (unless very cleverly written) walks across the length of the string looking for a null character. This is what your loop really looks like:

for (int i = 0; ; i++)
{
  size_t len = 0;

  while (read[len] != '\0')
  {
    ++len;
  }

  if (i >= len)
  {
    break;
  }
}

The for loop is walking over the length of the string, and strlen is walking over the length of the string. So the complexity of the loop, instead of the expected O(N), is really O(N^2). Pretty awful when you consider that correcting the error is trivial:

for (size_t i = 0, len = strlen(read); i < len; i++)

>line = atoi(read)/(int)pow((float)10, (float)strlen(read)-i-1);
That's about as close to concentrated evil as …

BluMan commented: Thanks for giving this advices! +0
Narue 5,707 Bad Cop Team Colleague

>So have your routine choose either 0 or 1 (so use rand() % 2)
>and then select the appropriate number with an if statement.
rand() % 2 is especially risky when it comes to getting the same result every time (for reasons I'm not interested in detailing at the moment). This has worked better for me in the past:

if (rand() < RAND_MAX / 2)
{
  /* Pick one number */
}
else
{
  /* Pick the other number */
}
Narue 5,707 Bad Cop Team Colleague

>Shouldn't the terminology be taught early on
>with stuff like cout, variables and if statements?

If only it were that easy. For example: super/sub, parent/child, base/derived. They all mean the same thing. Good luck teaching which one is appropriate in which situation without completely confusing the student.

The problem isn't in using/understanding correct terminology, which is all well and good when you can manage it. The problem is lack of common sense and imagination, as well as lack of research. Most terms can be figured out by a reasonably intelligent person with minimal effort. The rest of them can be gleaned through research.

Narue 5,707 Bad Cop Team Colleague

The operator= you define is for the Vertex class. It only applied when you assign something to a Vertex object. What you apparently want is an implicit conversion:

class Vertex
{
public:
	Vertex();
	operator double() { return value; }
private:
	double value;
};
nkinar commented: Great post; and extremely enlightening! +0
Narue 5,707 Bad Cop Team Colleague

What did you do to solve your problem before running here with your tail between your legs?

Salem commented: yap yap yap yap yap yap yap ;) +20
Narue 5,707 Bad Cop Team Colleague

>I just can't seem to compile it.
>Will someone please give me some suggestions?

I'd suggest reading the errors, tracing the source of the problem, and applying a fix to the code. What were you wanting us to do? Debug your code and give you the working program? Do you want fries with that?

Narue 5,707 Bad Cop Team Colleague

>What I need is TWO rows SKIPPED at regular intervals.
That's even easier. Now you're just filling in a two dimensional array using a one dimensional array, then incrementing the row counter by two at the end:

#include <iostream>

#define add_vector(m, rows, cols, next, v, vsize)\
do {                                             \
    int vi = 0;                                  \
    while (vsize - vi >= cols && next < rows)    \
    {                                            \
        for (int i = 0; i < cols; i++)           \
        {                                        \
            m[next][i] = v[vi++];                \
        }                                        \
        ++next;                                  \
    }                                            \
    next += 2;                                   \
} while (0)

int main()
{
    int v[9] = {1,2,3,4,5,6,7,8,9};
    int m[25][3] = {0};
    const int vsize = 9;
    const int rows = 25;
    const int cols = 3;
    int next = 7;

    add_vector(m, rows, cols, next, v, vsize);
    add_vector(m, rows, cols, next, v, vsize);
    add_vector(m, rows, cols, next, v, vsize);

    for (int i = 0; i < rows; i++)
    {
        for (int j = 0; j < cols; j++)
        {
            std::cout<< m[i][j] <<'\t';
        }

        std::cout<<'\n';
    }
}
Annettest commented: Thanks for your patience. +1
Narue 5,707 Bad Cop Team Colleague

>How should I change that definition to make it accept the {, , ,} directly?
Use a different language that supports such an overload or wait until C++0x comes out? You certainly have options, but the array initialization list isn't one of them. Your best option presently, in my opinion, is the iterator pattern found in the standard library:

cMatrix(Iterator first, Iterator last);

Then you can kind of cheat with an array to get a similar effect at the cost of an extra object:

double array[2]={1,2};
cMatrix mat(array, array + 2);

And if your matrix meets the basic sequence container requirements, you can use the standard library functions that work with containers.

Another (less recommended) alternative is setting up a constructor with a variable number of arguments:

#include <algorithm>
#include <cstdarg>
#include <iostream>

template <int N>
class Array {
    int _base[N];
    std::size_t _size;
public:
    Array(std::size_t n, ...)
    {
        va_list args;
        va_start(args, n);

        std::size_t i;

        // Fill in the "initializer" values
        for (i = 0; i < N && i < n; i++)
        {
            _base[i] = va_arg(args, int);
        }

        // Pad if size() > n
        while (i < N)
        {
            _base[i++] = 0;
        }

        va_end(args);
    }

    std::size_t size() { return N; }
    int& operator[](std::size_t i) { return _base[i]; }
};

int main()
{
    Array<10> a(5, 1, 2, 3, 4, 5);

    for (std::size_t i = 0; i < a.size(); i++)
    {
        std::cout<< a[i] <<'\n';
    }
}

It's trickier to do safely and slightly awkward, but probably the …

Narue 5,707 Bad Cop Team Colleague

>can some through some light that why is it behaving like this ?
It would truly suck for testing if rand weren't default seeded to a predictable value. As such, if you don't call srand, the program will behave as if you called srand(1) .

>time_t t;
>time(&t);
>srand(t);

The one-liner is generally preferred:

srand((unsigned)time(0));

But this is C++. We can do better by wrapping everything in a class and letting the object do all of the grunt work:

#include <cstdlib>
#include <ctime>
#include <iostream>

class Random {
public:
    Random(bool seed=true)
    {
        if (seed)
        {
            std::srand((unsigned)time(0));
        }
    }

    double get()
    {
        return std::rand() * (1.0 / (RAND_MAX + 1.0));
    }

    int next(int hi)
    {
        return (int)(get() * hi);
    }

    int next(int lo, int hi)
    {
        return (int)(lo + get() * (hi - lo));
    }
};

int main()
{
    Random r;

    for (int i = 0; i < 10; i++)
    {
        std::cout<< r.next(1, 6) <<'\n';
    }
}
The ICE Man commented: Good One :) +0
Narue 5,707 Bad Cop Team Colleague

>With reinterpret_cast it compiles, but the output is garbage.
I'm not surprised. Let's not forget that you're working with pointers and not float/double directly.

>What do you mean an overflow test?
Let's make it easier to visualize. Would you be wary about saying a = b when a is a short and b is a long int? If you answer "no", I'll whack you with a cardboard tube.

jonsca commented: So violent!! +4
Narue 5,707 Bad Cop Team Colleague

C++ doesn't allow the binding of temporary objects to non-const references. Your overloaded operator+ is returning a temporary object, which you then try to pass as a non-const reference to the overloaded operator=.

You can fix it by being const correct (a good idea anyway):

dummy& operator=(const dummy &rhs)

Note that const should generally be used if you aren't modifying the parameter. That guideline usually makes problems like this one go away.

Narue 5,707 Bad Cop Team Colleague

>can you please explain the whole code ? i'm just stuck !!
Nobody is going to explain the world to you just because you're clueless. Turn on your brain and figure it out yourself, or come up with specific questions if you still need help.

Narue 5,707 Bad Cop Team Colleague

>Everyone has told me to "Use Yacc/Lex" (or various variants
>of them), but I really don't understand how they're useful.

Then you don't know enough about how compilers work or how they're implemented. In such a case it's a bad idea to use tools because even if you end up with a usable result, you probably still won't understand it. You should get your hands dirty and write a compiler (even a simple one) by hand at least once.

Narue 5,707 Bad Cop Team Colleague

@jephthah

>um, search the filename string for a ".com" extension? yes?
No. What kind of simpleton would do a naive extension search when the extension is largely ignored by the program loader? AV writers need to be smarter than that, because virus writers definitely are.

>it's pretty clear that you're trying to make some sort of malicious software.
I don't think it's clear at all.

>viruses aren't written in assembly, you silly person.
Wow, are you drunk? Of course viruses are written in assembly. They're written in other languages too, with C and assembly being the most common, last I checked.

@Th3one234

>But could a COM exectuable not be renamed to have a different file extension?
Absolutely. COM executables are raw instructions with no format, so there's not a solid way to detect them. You could start by looking for a jump as the first instruction (a common occurrence in COM executables), or come up with some heuristics for guessing whether the first N bytes represent machine code.

Alternatively you could assume that anything without a known non-threatening format or default loader is potentially malicious and scan it anyway.

>C is far too restrictive on many levels to write effective viral applications.
I disagree. The strongest viruses are more likely to be written in assembly due to the need for increasing need for clever hiding strategies, but you'll find that many effective viruses have been written in C …

jephthah commented: huffing ether, actually. :-/ +7
Narue 5,707 Bad Cop Team Colleague

>Not grammatical. Semantic.
Whatever. Exchange one triviality for another and the result is still trivial.

>Again you misrepresent me.
I call it like I see it. If you don't want to be misrepresented, take more care in presenting yourself. Someone so focused on semantics should have no trouble with that.

Narue 5,707 Bad Cop Team Colleague

>and why we are checking this condition ? if(num[i]>num[j]) Why would you want to swap items that are already in the correct order?

Narue 5,707 Bad Cop Team Colleague

>I don't know what it is that the member is actually given.
An infraction (as used on Daniweb) is a flag placed on a member's account as notification that the member broke a rule. It's pretty much what one would expect. I'm rather surprised you didn't come up with any alternatives (even ones based on speculation about the meaning) before posting your "suggestion".

Typically suggestions will point out a problem and offer a viable solution. Pointing out a problem without offering a solution implies that you couldn't think of a good solution, which makes the problem seem like far less of a problem.

Narue 5,707 Bad Cop Team Colleague

>If you find any grammatically mistake or you have better
>way of explain the point, please do not hesitate to correct.

Which amounts to rewriting your prose, I'm afraid. It's very clearly written by someone with grammar habits from another language, and those habits are hard to break with a few quick corrections. A dedicated editor with strong English writing skills would be better.

>If you have any trick or useful information related to C++, do not hesitate to share.
I have tons of them, but random collections are rarely useful. Do you have any specific direction you want to take things? What's the target audience?

>1st Piece: Reduce the Calculation
Simplifying expressions, good. Simplifying at the cost of readability, not so good. 180 is pushing it for magic numbers, and 0.0174532925 is outside the realm of good taste. You should make use of manifest constants in your examples to promote good practice.

>2nd Piece : Everything Is Not the Same
Here's another piece of advice: Don't sweat the small stuff. In the majority of cases, arithmetic won't make up the lion's share of your processing time, and a decrease in readability for dubious enhancements is rarely a win. I cringe every time I see someone do something silly like convert k *= 2 to K <<= 1 or K += k and expect huge performance improvements when their code is I/O bound in the first place. :icon_rolleyes:

invisal commented: Thank for advice. +6
jonsca commented: Sound ideas as usual +4
Narue 5,707 Bad Cop Team Colleague

>I am not asking about a qualified id
I know that, and if you were reading for comprehension, you wouldn't have been so quick to dismiss my answer.

>&test::d // which is what I believe 5.3.1 paragraph 2 quoted by Narue refers to
Dude, read the whole freaking paragraph. It even starts with the material that you're looking for:

The result of the unary & operator is a pointer to its operand. The operand shall be an lvalue or a qualified-id. In the first
case, if the type of the expression is “T,” the type of the result is “pointer to T.”

In your example, t.d is an expression resulting in an lvalue with a type of double, thus &t.d legally produces a result of pointer to double. Section 5.2.5 confirms that t.d is an lvalue.

If you want to get answers from the standard, you can't gloss over whole sentences.

Narue 5,707 Bad Cop Team Colleague

"void mainers are DOOMed"
"Geeks Lounge Junkie"
"Banned"
"Programming Forums Survivor"
"What is Area 51?"
"Superduper Mod"

jephthah commented: "Banned" LOL. now that's pure awesomness. +0
sureronald commented: I like it +0
Narue 5,707 Bad Cop Team Colleague

>vectro, problem!
>I am making a speel check program
>Is this labary in Turbo/borland c++ difrent or what?
>Uneable to open include file

Good choice of problems to solve. A spell checker is clearly needed here.

>i have a problem with the libary #include <vector.h>
<vector.h> is not a standard library. The vector template class resides in the standard header <vector>. All bets are off, and the recommendation you're most likely to get is upgrade your compiler and modernize your code.

Narue 5,707 Bad Cop Team Colleague

>so I want to define a casting function:
>double(signum s)

So do it. We're not talking about rocket science here:

double to_double(signum s);

Or are you going to complain that double(s) is so vastly superior to to_double(s) that you absolutely must have a user-defined cast that uses exactly the same syntax as the native cast? :icon_rolleyes:

Salem commented: Quite. +20
Narue 5,707 Bad Cop Team Colleague

>I rather not use conio.h for cross compatibility
Good idea.

>is there any way to make my own "conio.h" and just include it in my compilation
Um, conio.h offers functionality that's non-portable by nature. No matter how you do it, you'll end up rewriting your replacement for every target to maintain portability. Is it possible to reproduce the functionality of conio.h? Absolutely, but all of those methods are (surprise surprise!) non-portable. Thus, you're right back where you started.

My usual recommendation with conio.h is to seriously consider whether it's needed in your program. Most of the time it's not.

Narue 5,707 Bad Cop Team Colleague

>can anyone post the full edited code here...plzzzzzz
How helpless can you be!? I gave you the working loop. All you need to do is cut and paste, Einstein. Geez.

Narue 5,707 Bad Cop Team Colleague

>in the above link they are saying, user should definitely NOT write code of the form
They're wrong. That code (ignoring gets) is best practice. Assuming for a moment that the author of that page isn't an idiot, I'd say there's an implicit assumption about the system/implementation here:

let the implicit output-flushing routines handle everything for you

There are two implicit flushing "routines":

  1. When a newline character is sent to the output stream in question.
  2. When the output stream buffer is full.

It should be obvious that #2 can't be relied on if you want your user prompts to show up...well, promptly. If you want user input to be on the same line as the prompt a newline at the end of the prompt to force a flush isn't practical. The only other way to flush the stream is fflush.

The truly humorous part is how the biggest argument against fflush from that page is overhead. Let's think about this logically using the two examples:

/* Example 1 */
printf("Prompt: ");
fflush(stdout);
gets(s);
/* Example 2 */
printf("Prompt: ");
gets(s);

Assuming the "implicit flushing routines" handle everything for you, one would expect both prompts to show up before gets blocks for input. This is the normal expected behavior, and if the second example fails to do it (because there's no flush), that's a strong argument in favor of using fflush.

However, if both examples do show the prompt correctly, that means under …

urbangeek commented: her answer resolved all my queries, even those i didn't ask!! :) +0
Narue 5,707 Bad Cop Team Colleague

>cout << &n << endl;
As I suspected, you're printing the address of the iterator object. You want to print the referenced object instead, which can be done by dereferencing the iterator first:

cout << &*n << endl;
Narue 5,707 Bad Cop Team Colleague

The color you want is initColor(FOREGROUND_GREEN | FOREGROUND_INTENSITY) . And it's generally more informative to use the macros rather than hardcoded values.

Narue 5,707 Bad Cop Team Colleague

>According to this article you are wrong
On the contrary, I'm more correct than the article. :) The standard places hard minimum limits. Implementations are free to exceed those limits, but going below them would be non-conforming. The article you linked to isn't wrong per se, but it does omit the part about minimum requirements, which could be misleading.

jephthah commented: awesome +7
Narue 5,707 Bad Cop Team Colleague

>how does long and long long differ?
long was originally intended to be 32 bits and long long to be 64. These are the minimum limits though, so as the need for longer types grows, they could grow to accommodate it.

>Was short type ever was 1 byte and changed to 2 bytes later on?
No, short has always been at least 16 bits.

>Was long and int ever was 4 byte and 2 bytes respectively?
The minimum for long is 32 bits, and the minimum for int is (surprisingly to some) 16 bits. So you could say that long is at least 4 bytes and int is at least 2 bytes presently (assuming an 8-bit char type), but could be more depending on the implementation.

>double = "%lf"
This is for scanf, by the way. printf performs default promotions such that everything is double, and thus the unadorned floating-point specifiers are sufficient. Note that "%lf" is undefined in C89 and a the length modifier is ignored in C99.

>long double = "%llf"
That would certainly be consistent with long long, but sadly, "%llf" is undefined behavior. long double uses an upper case L: "%Lf".

Narue 5,707 Bad Cop Team Colleague

>could there be a way to press SHIFT first and after 'a' ?
Yes, there could. You also have the tools necessary to figure it out. Give it a shot.

Narue 5,707 Bad Cop Team Colleague
if ( GetAsyncKeyState ( VK_SHIFT ) && GetAsyncKeyState ( 0x41 ) ) {
  // SHIFT+A combination pressed
}
Narue 5,707 Bad Cop Team Colleague

>Okay, while continuing to search, I came up with this:
>http://msdn.microsoft.com/en-us/libr...=VS.80%29.aspx

_Smanip is a Microsoft-ism. Don't expect code using it to compile anywhere except Visual C++. The concept behind _Smanip is trivial anyway:

#include <iostream>
#include <iomanip>

struct fillblank {
  int _l;

  fillblank ( int l ): _l ( l ) {}

  friend std::ostream& operator<< ( std::ostream& os, fillblank fb )
  {
    for ( int i = 0; i < fb._l; i++ )
      os << ' ';

    return os;
  }
};

int main()
{
  std::cout << "10 blanks follow" << fillblank ( 10 ) << ".\n";
}

The arguments are actually constructor arguments, which are then stored as data members in a temporary object and an overloaded << operator is called on the stream using that temporary object. It's elegant and works very well.

Narue 5,707 Bad Cop Team Colleague

>i searched how to use three conditions in conditional operator but didn't find any where
Then I guess you didn't look in this thread. My first reply gives you this:

int d = a < b ? a < c ? a : c : b < c ? b : c;

My previous reply showed you a conversion to if statements from which you can derive the equivalent code:

int d;

/* d = a < b ? a < c ? a : c : b < c ? b : c */
if ( a < b ) {
  if ( a < c )
    d = a;
  else
    d = c;
}
else {
  if ( b < c )
    d = b;
  else
    d = c;
}
Narue 5,707 Bad Cop Team Colleague

>why it is printing the Maximum value among those three input values ?
It isn't. If b is greater than or equal to a, but c is less than b, your code will erroneously print c rather than b. It helps if you write the equivalent if statement to see the logic flow:

/* d=a>b? b>c? a:b:c */
if ( a > b ) {
  if ( b > c )
    d = a;
  else
    d = b;
}
else {
  d = c;
}
Xufyan commented: Ty.:)..Xufyan +0
Narue 5,707 Bad Cop Team Colleague

>but i cannot give these answer to my students.
Sure you can. When teaching a complex subject of interrelated parts, it's generally best to gloss over the parts that aren't absolutely necessary at the student's level.

Narue 5,707 Bad Cop Team Colleague

Gibberish typically means you failed to terminate a string with '\0'.

formulajake88 commented: Solved the problem! +0
Narue 5,707 Bad Cop Team Colleague

>i was trying to find code or solution without using stdlib.h
Unless you need something stronger than rand, it's best to keep to the standard libraries. However, implementing your own random number generator is an entertaining exercise.

>May I ask if Is it safe to download Turbo C in brothersoft.com
If I say "NO! It's a virus!", will you forget about Turbo C and use a more up-to-date compiler? I'm not against lying if it benefits everyone. :D

Aia commented: Liar! It is a trojan! :D +8
jonsca commented: Can't say you didn't try... +3
Narue 5,707 Bad Cop Team Colleague

const is a qualifier for objects that tells the compiler you won't try to modify the object's value:

int x = 10;
const int y = 10;

x = 20; /* Okay */
y = 20; /* Bzzt! y is const */

const is short for constant, which really means read-only[1] rather than truly constant. It's typically used for pointer parameters that shouldn't be modified:

void print_chars ( const char *s )
{
  while ( *s != '\0' )
    putchar ( *s++ );
}

int main ( void )
{
  print_chars ( "This is a test" );
  return 0;
}

In the above code, a string literal is passed to print_chars. String literals reside in read-only memory, which means trying to modify them could potentially cause a runtime error. print_chars doesn't need to modify the string passed, so it specifies the parameter as const to tell callers that it's safe to pass string literals.