Narue 5,707 Bad Cop Team Colleague

Assuming you have control over glutMouseFunc, you need to overload it to accept a pointer to a member function:

class Plot {
public:
  void MouseButton();
};

void glutMouseFunc ( void (Plot::*pmf)() )
{
  //...

  Plot p;
  (p.*pmf)();

  //...
}
Narue 5,707 Bad Cop Team Colleague

I'll go out on a limb and guess that you're using Visual C++ 6.0, where your problem is a known bug.

William Hemsworth commented: Good guess :) +3
Alex Edwards commented: From C++ expert to Psychic? Whoo! =P +4
Narue 5,707 Bad Cop Team Colleague

I'm looking at the site in Firefox presently, and everything seems fine. What do you mean by "it didn't work properly"?

Narue 5,707 Bad Cop Team Colleague

Command line arguments are passed as parameters to main. The first parameter gives you the number of arguments (including the program name) and the second gives you an array of strings containing the actual arguments:

#include <iostream>

int main ( int argc, char *argv[] )
{
  // The first argument is the program name, if available
  if ( argc > 1 ) {
    for ( int i = 1; i < argc; i++ )
      std::cout<< argv[i] <<'\n';
  }
}
Narue 5,707 Bad Cop Team Colleague

>no i cant.
So what you're saying is that you're unwilling or incapable of searching Daniweb, Google, or any book on C. This is a dreadfully simple problem and the question is asked quite frequently.

>can you pls help me?
No, you're beyond help. If you can't be bothered to do simple research, we can't be bothered to spend our valuable time on a lost cause. Come back when you've actually attempted to help yourself first.

Nick Evan commented: yup.. +8
Narue 5,707 Bad Cop Team Colleague

Remove it from printf, but not scanf. Like this:

fscanf(fp,"%d %d %lg", &i_in, &j_in, &p_in);
/* ... */
printf("i_in: %d \n j_in: %d \n Value: %lg \n", i_in,j_in,p_in);
Narue 5,707 Bad Cop Team Colleague

>printf("i_in: %d \n j_in: %d \n Value: %lg \n", &i_in,&j_in,&p_in);
You're printing the value of the address of each of those variables. Remove the address-of operator.

Narue 5,707 Bad Cop Team Colleague

What have you tried so far?

Narue 5,707 Bad Cop Team Colleague

>I was wondering if a mechanism like the "Flag Bad Post"
>option on forum posts would be useful on the PM interface.
I'm torn on this. On the one hand it's a good idea. On the other, we don't have the rule framework in place for dealing with problematic PMs. Presently it's most often dealt with on a case by case basis by Dani, happygeek, and myself.

>Every time that I've received one of these messages
>I've been unsure as to who I should forward the message.
Forward them to me and I'll either deal with them personally, or pass them on for discussion by the admins and mod team.

Narue 5,707 Bad Cop Team Colleague

>Would you mind explaining why this is illegal?
The short answer is that it's not a constant expression, which is required.

Narue 5,707 Bad Cop Team Colleague

>flush is a function so you need to use () cout.flush()
std::flush is a manipulator, that part was fine.

>Try this macro
That still won't work as the construction is illegal.

>What I'd like is a way to print the information at compile-time.
That brings up the question of where and how you intend to print it. At compile-time you can really only rely on compiler-specific methods for outputting compile-time messages. You can get close with something like this:

#include <iostream>

#define STR(x) #x
#define TOSTRING(x) STR(x)

template <int N>
struct PrintInfo {
  enum { 
#pragma message(TOSTRING(N))
    RESULT = N + PrintInfo<N - 1>::RESULT 
  };
};

template<>
struct PrintInfo<0> {
  enum {
#pragma message("0")
    RESULT = 0
  };
};

int main()
{
  int result = PrintInfo<5>::RESULT;

  std::cout<<"Result: "<< result <<'\n';
}

But, because the preprocessor runs before template instantiation, you'll only see a bunch of N's rather than the actual value of N for each instantiation.

I'm not a template metaprogramming guru, so the only way I can think of to get a good compile-time output of each value of N is to specialize all of the values:

#include <iostream>

template <int N>
struct PrintInfo {
  enum {
    RESULT = N + PrintInfo<N - 1>::RESULT
  };
};

template<>
struct PrintInfo<0> {
  enum {
#pragma message("0")
    RESULT = 0
  };
};

template<>
struct PrintInfo<1> {
  enum {
#pragma message("1")
    RESULT = 1
  };
};

template<>
struct PrintInfo<2> {
  enum {
#pragma message("2")
    RESULT …
Alex Edwards commented: Simply amazing... =) +4
Narue 5,707 Bad Cop Team Colleague

>I can't get my program working when I put !finBinary.eof().
Put it where? Why don't you post the code you're asking a question about so we don't have to guess?

>Google'ed and found out that binary files have some characters similiar to eof?
That's a different eof. There's the physical representation (if there even is one on your system) for end-of-file that's stored in the file, and there's the end-of-file flag within standard C++ streams. The latter is what you're trying to use, and it will work properly regardless of the orientation of your stream. Most likely your code is wrong.

>So I decided to use the seekg and tellg, which gives me a weird number
That weird number is most likely the number of bytes in the file (not the number of records, unless a record is one byte), which is what I would expect on most implementations.

>I'm still interested to know how to get the number of records in a binary file
The same way you get the number of records in a text file. The only 100% portable method is to read them all:

Record record;
int n = 0;

while ( next_record ( in, record ) )
  ++n;

Of course, given this knowledge it makes sense that the best solution if you can manage it is to process all of the records as you read them to avoid reading them twice.

Narue 5,707 Bad Cop Team Colleague

>Now it somehow skips straight to 'else', missing out the 'if' and the 'else if'......
That's because getch doesn't perform text conversions. It's a straight detection of scan codes from the console. This means that on systems (such as Windows) where a newline is two values before being converted to '\n' by C++'s stream buffer, calling getch once will give you the first of those values.

Assuming you're on Windows, here's what is happening. When you press Return, a Windows newline is signaled and two values are sent to the console: 0xD and 0xA, in that order. This is the CR-LF pair you may have heard about. Let's say that '\n' in C++ represents 0xA. A standard C++ text stream will take 0xD-0xA and compact it into 0xA, but getch won't do anything of the sort and will simply return 0xD.

So the result is that you're comparing 0xD with 0xA, which is clearly not true, so the else statement is performed. You can catch the carriage return using the '\r' escape character:

#include <iostream>
#include <conio.h>

const int ESC = 0x1B;

int main()
{
  int a;

  while ( ( a = getch() ) != ESC ) {
    if ( a == '\r' )
      std::cout<< a <<"\tNewline detected\n";
    else
      std::cout<< a <<"\tNot a newline\n";
  }
}
Narue 5,707 Bad Cop Team Colleague

Inclusion guards are a preprocessor trick. If a macro with a unique name for that header is not defined, proceed to process the header. If it is defined, don't process the header. The macro itself is defined during the processing of the header, so the result is that the header is only processed once:

#ifndef FORM13_H
#define FORM13_H

// Your existing header contents go here

#endif
Narue 5,707 Bad Cop Team Colleague

Are you using inclusion guards in Form13.h?

Narue 5,707 Bad Cop Team Colleague

>I know it's good programming practice to make
>accessor's const. But does it impact speed.
It can, but usually nowhere close to as much as many people believe. const is more for your benefit because it helps make your code easier to work with by adding compile-time invariants.

>Will I get any performance gains by using static keywords, where ever it's possible
Possibly, but it really depends on what you're doing. For example, let's say you have an array of large objects that won't fit in a single cache line. Hoisting some of the data members into statics (if possible) could drop the size of each object to the point where the array fits in a cache line and you might see a sudden and significant increase in performance.

>Will I get any performance gains by using const keywords, where ever it's possible
If saying yes will get you to use const more, then yes. :)

>I never use the "smart" stuff, like protected and
>virtual function. Should I start looking into this.
If you don't need it, don't use it. But if you don't understand it, you don't really know if you don't need it.

>According to <snip url> the virtual functions are especially to avoid.
Virtual functions have an overhead that needs to be considered. But that implies a trade-off, not an "avoid this feature" guideline. I highly recommend you take such advice with the context in …

Alex Edwards commented: Very nice post! =) +4
Narue 5,707 Bad Cop Team Colleague

>The first one is I'm wondering what is the best library to use for a hash table in a C++
It depends on what you need. Google's sparse hash library is nice, and if you can find a good implementation of TR1 (such as Dinkumware), you can use the hash_set and hash_map classes.

>what do you guys use?
I currently use TR1 (first my own implementation, now Dinkumware).

>Or do you implement your own?
In C I implement my own. In C++ I used to implement my own until I gained confidence in third party implementations that matched the interface I wanted to use. I don't recommend rolling your own hash table unless you really know what you're doing.

>what kind of IDE do you use to edit and compile your programs?
I don't use an IDE. I use some flavor of vi and make.

>Is there a good windows / linux based GUI for working with g++?
Code::Blocks is a good IDE, and it's available for several Linux distributions.

Narue 5,707 Bad Cop Team Colleague

>do you mean there is no difference in any thing when I
>use <windows.h> in C langauge and when I use it in C++ ?
More or less.

>then why they say programming win32 by C and programming win32 by C++..!?
Probably because it's true. "Win32 by C" means a C program that uses Win32. Likewise, "Win32 by C++" means a C++ program that uses Win32. C and C++ are different languages, so it's a rather important distinction even if <windows.h> is usable in both.

Narue 5,707 Bad Cop Team Colleague

>In my example, Do you mean the default behavior is call the operator= of class B?
I fail to see how my reply was ambiguous. You want a member array to be properly copied even in the case where a non-default copy constructor or assignment operator exists for the array type, and that's what happens. Therefore, saying that the default behavior will do what you want is a complete answer to your question.

>If the default behavior is just memory copy and class B
>have pointer member, it will produce a undefined result.
That's strictly a quality of implementation issue for class B. If B implements a copy constructor/assignment operator then A will have to call it when copying any object of B, even if the object of B is a member of an array.

Narue 5,707 Bad Cop Team Colleague

That's a classic error. It means you created a Win32 application project but wrote code for a console mode application. The former requires WinMain instead of main as the entery point.

Narue 5,707 Bad Cop Team Colleague

>but why they say ..:programming under win32 using C language ..!
You're using the C language to access the Win32 API through a C interface (the header and library).

Narue 5,707 Bad Cop Team Colleague

<windows.h> is from the Win32 API.

Narue 5,707 Bad Cop Team Colleague

>but I would like to know how many libraries on C language until today is there any location.?
There are thousands upon thousands of C libraries. And no, there's no centralized location.

Narue 5,707 Bad Cop Team Colleague

>so my qusetion is that :I need to know how many
>the libraries under C language until this day.. ?
It sounds like you just want to focus on Win32 for now. You can start here, but eventually you'll be checking MSDN regularly.

Note that GUI programming is not easy as there's quite a learning curve when coming from console applications.

Narue 5,707 Bad Cop Team Colleague

>Does it need a copy constructor and an operator= for a class which have array member?
No, the default behavior will do what you want.

Narue 5,707 Bad Cop Team Colleague

Polymorphism is a category of programming language features that meet certain requirements[1] and overloading is a member of that category.

[1] Specifically: using the same name to refer to and work with different entities in a safe and well-defined manner.

Narue 5,707 Bad Cop Team Colleague

>in C/C++
This is the C# forum.

>it can be any boolean expression or any statement with some integer value
IIRC, the description is "any expression that can be contextually converted to bool".

>or no value at all(in this case it is considered true always)
This is incorrect. Failure to provide a condition expression is a syntax error.

>but if the code is for java
This is still the C# forum. Conveniently enough for you, the Java rule matches C#.

Narue 5,707 Bad Cop Team Colleague

i thought this thread was about "strangling newbies"

imagine my dismay when i found a ten-mile long post full of incoherent code with no syntax coloring.

That was completely uncalled for, jephthah. If you're going to take the path of the angry programmer, at least try to follow the lead of the successful ones. There's a fine line between tough love and violating Keep It Pleasant.

And for future reference, the highlighting feature of code tags is optional. You should be thrilled the OP used code tags at all. It could have been pages and pages of unformatted line noise rather than relatively well formatted and clean Perl code. I see no reason for complaint.

Narue 5,707 Bad Cop Team Colleague

>I Believe my problem is that the string is in a "private" object
That's the way it should be. I've had to smack co-workers on the head before for solving this problem by making those data members public. :icon_rolleyes: Anyway, you can access the data from another form through properties as long as you have an object of the form:

internal class FormA: Form {
  // ...

  public FormA()
  {
    InitializeComponent();

    using ( FormB dlg = new FormB() ) {
      if ( dlg.ShowDialog() == DialogResult.OK ) {
        using ( StreamWriter sws = new StreamWriter ( "Settings.txt" ) )
          sws.WriteLine ( "rate \"" + dlg.Rate, "\"" );
      }
    }
  }
}

internal class FormB: Form {
  private string asRate;

  public string Rate
  {
    get { return asRate; }
  }

  // ...

  private void asBtnOk_Click ( object sender, EventArgs e )
  {
    asRate = asBoxRate.Text;
  }
}
Narue 5,707 Bad Cop Team Colleague

The condition must evaluate to a boolean type. Unless result[1] is already a boolean type, you can't use it without a relational test:

String str = ( (String)result[i][1] != null ? (String)result[i][1] : "" );

Also, what type is result[1] such that a cast to String is required?

Narue 5,707 Bad Cop Team Colleague

Viewing the "machine code" is pretty much a silly idea. More likely you want to see the assembly code that corresponds to the machine code. In that case there are two easy ways depending on whether you have the C++ code available or not.

If you have the source code, simply compile it with whatever switch your compiler provides for assembly output. Most likely you'll get some easy to read assembly with the matching C++ source interspersed as comments so you have a better idea what's going on.

If you don't have the source code but you do have an executable, you can use a tool like OllyDbg that gives you detailed information on the runtime execution as well as a good disassembly.

Narue 5,707 Bad Cop Team Colleague

>Anyone considerinstalling Vista -- don't. You will have nothing but headaches.
I've only had one problem with Vista, and it wasn't caused by Vista. But I fixed that particular issue (with my graphics card driver) and now everything is just peachy.

>I say try it out first, off a friend who has it, or in a store.
That only serves to test whether you can tolerate the interface. It doesn't give you any idea how Vista will run on your system.

If you look back in the annals of Windows, you'll discover that XP had the exact same problems. People were whining that XP was too slow, and XP was incompatible with everything, and XP was crap. If you take just about any complaint about Vista and replace "Vista" with "XP", it's like deja vu. But how many people now running XP would be willing to drop back to Windows 98 or NT?

Narue 5,707 Bad Cop Team Colleague

>Do you think that an old compilator can differ a magnitude order from the new one?
Yes. Especially since Visual C++ 6.0's STL implementation was extremely weak.

>Can I do easily a dll for windows without using Microsoft Visual C++ compilator?
Writing DLLs in Windows is not difficult. Though I would highly recommend upgrading your Visual C++ to 2005 or 2008. Visual C++ 6.0 is painful if you plan on making use of templates.

Narue 5,707 Bad Cop Team Colleague

>how to store the position and count of particular word into another arrays.
Yes, let's be clear. Do you need the position of a word in a string for any other reason than to find the count of that particular word? Or is that simply an implementation detail?

If you really do need it, and you're not just regurgitating Compton11's proposed solution, you need to start over with a full description of the requirements, because that requirement was absent in your original request.

If you don't need it, I'll continue to recommend you forget that particular solution and use scanf to separate the words. That way you can more easily store and count them.

>and i don;t want the full program from u.
If I give you any more code, the problem will be solved. That's how easy it is.

Narue 5,707 Bad Cop Team Colleague

>Please help me.
Give me a good reason why I should. I've already helped you more than you deserve, and you ignored me completely.

>But no one give any solutions
That's because someone[1] isn't comprehending the replies. Not only did I give you a superior alternative to gets with a working example (thus solving half your problem), I described an easy way to solve the other half. I'm not going to do it all for you, so engage your brain and try again.

[1] That someone is you, vijaysoft1, in case you were wondering.

Narue 5,707 Bad Cop Team Colleague

>Well, i believe that a simple thanks is enough for you and for your try.
Yet given two opportunities, you've failed to offer even that. Your first reply was a whiny flame and your second dismisses my effort as a "try" before proceeding to focus completely on my behavior (which was quite mild and objective).

>You make me mad due to yours behavior.
Then you should be absolutely furious due to your behavior. Let's look at my behavior, if that's what you want, and hopefully you'll see that your response was completely out of line. Here's the only possible statement I made that could be seen as rude by any measure before you decided to make an ass of yourself:

It's not often that looking at code can leave me speechless.

Given the many errors and issues I then objectively pointed out, this statement is one of fact about the code and clearly not aimed at you as the programmer. If you took offense, that's your problem, but keep in mind that treating my legitimate help as an attack means that you are at fault in terms of rudeness.

I won't demand an apology, because I honestly don't care about winning or losing an argument against someone such as yourself, but I will strongly recommend that you consider your behavior and adjust your attitude before posting again. Not because I'm a moderator, as the rules themselves dictate how you must act on Daniweb (I don't put …

Narue 5,707 Bad Cop Team Colleague

Have you looked into using templates for your containers?

Narue 5,707 Bad Cop Team Colleague

>that is the code for decimal to binary...
That's pretty awful. At least it kind of works.

>#include <conio.h>
You don't even use anything from this header, why destroy portability by including it?

>void main()
Here is the only correct definition of main with no parameters:

int main ( void )
{
  /* Your code here */

  return 0;
}

The return value can be any integer you want, but the only portable ones are 0, EXIT_SUCCESS, and EXIT_FAILURE. The latter two are macros defined in <stdlib.h>. Anything except what I've described is non-portable. For a definition of main that takes parameters, the following is the only correct definition:

int main ( int argc, char *argv[] )
{
  /* Your code here */

  return 0;
}

There are only two parameters. The first is an integer and the second is a pointer to the first element of an array of pointers to char. Any equivalent type is allowed, and the identifiers can be whatever you want (though argc and argv are conventional), for example:

typedef int FOO;

int main ( FOO ac, char **av )
{
  /* Your code here */

  return 0;
}

Anything else is non-portable.

>int n, a[30],i=0;
I'm gradually becoming more and more hostile toward this practice. It's a great way to hide variable declarations from readers, and it's also a great way to make maintenance more difficult. I've reached this conclusion after having to change …

Narue 5,707 Bad Cop Team Colleague

>I can not fathom what a post of yours, in full bloom speech mode would have meant.
You should have seen some of my diatribes on cprog. ;)

>I would say, the first clue is using namespace std; Which it works in C++ but not in C.
I was working under the assumption that the code was originally written in C++ and being ported to C by someone who isn't terribly familiar with C.

>fputs ( "The typed string into Ascii mode: ", stdout ); would
>need a followed call to fflush(stdout); for consistency.
That's unnecessary. fflush is only needed when one wants to explicitly flush the stream immediately. The most common cases for this are error logging and user prompts. For output that doesn't fall under the real-time requirement (as in this case), there's no need to flush right away. It would also be largely redundant as there's a call to puts after the loop that ends up flushing due to the printing of newlines, and a putchar at the end of the function that flushes as well.

>How would that call to strcspn() compare in over head and speed, to the classic:
It's invariably slower.

@SiRuS

>Ok Ok stop shotting me.
I took quite a bit of time out of vastly more important things to break down your code, show you what was wrong, and describe in detail why it was wrong as well as how to …

Narue 5,707 Bad Cop Team Colleague

Weak or unpolished graphics can distract from the gameplay in many cases. Likewise, attention to detail in the graphics can improve gameplay by drawing the player in and offering more variety in how elements are displayed. Compare shooting at red blobs with a frowny face to shooting at a noticeably frightening monster.

Narue 5,707 Bad Cop Team Colleague

>I run the code on a linux machine and gave me errors..
What errors? Posting your code and your assignment isn't conducive to getting help because it suggests that you want us to finish your project for you, which isn't going to happen.

Narue 5,707 Bad Cop Team Colleague

>I ended up having to do some research on why the cast the
>OP mentioned was legal, and I admit I still do not understand.
Put simply, the cast is an "I know what I'm doing" switch that turns off the safety net. In this case, and on the OP's implementation, it happened to work out.

>I did forget that ( Base* ) is a C-style cast and that I
>do not understand the way the compiler interprets it.
The cast says

"Here is an address. Pretend the memory at that address represents this type"

Since Base and Derived don't have any data, there's a very good chance that the object mappings will overlay perfectly, and accessing d's virtual pointer through a pointer to Base will produce the expected behavior. But let's pretend that Base and Derived have data:

#include <iostream>

class Base {
  const char *p;
public:
  virtual void foo() { std::cout<<"Base\n"; }
};

class Derived: private Base {
  const char *q;

  virtual void foo() { std::cout<<"Derived\n"; }
};

int main()
{
  Derived d;
  Base *p = (Base*)&d;

  p->foo();
}

For the sake of argument, assume that this is how an object of Base is represented internally:

Base::{ vptr | p }

And an object of Derived is represented like so:

Derived::{ Base::{ vptr | p } | q }

It's fair to say the cast will work, and the result will be polymorphic because taking memory originally mapped …

Alex Edwards commented: Thanks for a very detailed explanation on data mappings within objects, Professor =) +3
Narue 5,707 Bad Cop Team Colleague

>#include<conio.h>
I recommend you forget this header exists until you learn why it's a bad idea.

>void main()
main returns int.

>char *typed;
>gets(typed);
That's just brilliant. Not only did you fail to allocate memory to typed (who knows where those characters are being written), you chose to use gets despite the fact that it's impossible to use safely and ultimately one huge ugly wart on the face of C. Please use fgets instead.

Anyway, I'm not sure what Compton11 was thinking with his advice, but parsing a string makes this program more difficult. You can use scanf to read individual words:

#include <stdio.h>

int main ( void )
{
  char word[256];

  while ( scanf ( "%255s", word ) == 1 )
    puts ( word );

  return 0;
}

From there it's simply a matter of maintaining a list of words and the corresponding frequency. For a relatively short list of words, you can easily use two parallel arrays for this.

Narue 5,707 Bad Cop Team Colleague

>Hello guys this is my code.
It's not often that looking at code can leave me speechless.

>Can anyone help me please???
Sure. Let's start by looking at the fatal errors:

>char str[] = { 0 };
As much as many C programmers would love for this to declare a string of unlimited characters, it doesn't. It only allocates one character to the array, effectively giving you either a perpetually empty string (because a null character is required), or a glorified char variable.

>int* cVec = (int*)malloc ( alloc );
You strike me as a C++ programmer who's used to new[] for dynamically allocating arrays. malloc only accepts a byte count, not an item count, which means that on a system with four byte integers you're three bytes short on every item. This causes you to overrun the memory, which corrupts the memory manager, which nearly always results in free choking.

Those are your two fatal errors. They're extremely likely to result in a runtime crash. You also have a portability issues:

>unsigned int alloc = strlen ( value ) + 1;
strlen is declared in <string.h>, yet you don't include that header.

>//works in windows but not on linux
>//cVec[ i ] = int(value[ i ]);
Then you're compiling as C++ in Windows but not in Linux. This cast style is not supported by C. Also note that comments beginning with // are not supported except …

Salem commented: Always a breath of fresh air through mouldy code :) +20
Narue 5,707 Bad Cop Team Colleague

>I'd assume this is because of the padding factor
>and vtable pointers like you mentioned before.
It's because of a lot of things. Padding and alignment of data members are a factor, how the compiler implements runtime polymorphism, how the compiler handles virtual base classes, and any compiler optimizations.

Case in point for that last item, what would you expect the output to be for this program?

#include <iostream>

class foo {};
class bar: public virtual foo {};

int main()
{
  std::cout<< sizeof ( foo ) <<'\n';
  std::cout<< sizeof ( bar ) <<'\n';
}

Depending on whether the compiler implements a special case for empty virtual bases, and assuming a typical virtual implementation with 4 byte pointers and alignment on a word boundary, the output could be either 1 and 4 (most likely) or 1 and 8.

Narue 5,707 Bad Cop Team Colleague

>Not to nittpick, but 'cout' never belonged to the C-language
That's a different nitpick. The OP asked about cout, so it's relevant to this thread even if nobody bothered to move it to the C++ forum.

Narue 5,707 Bad Cop Team Colleague

>So the conversion operator is an operator without a symbol (that is no & or || or << or []) to represent it.
The conversion operator is an operator with a type to represent it, the type being the symbol.

>Operator overloading allows C/C++ operators to have
>user-defined meanings on user-defined types (classes).
Nit: C/C++ only makes sense when the feature/technique/convention is available both to C and C++. Operator overloading is not, nor are classes as defined by C++. Thus, when you say C/C++, you mean C++ and should say C++ to avoid furthering myths about the relationship between C and C++.

Narue 5,707 Bad Cop Team Colleague

>I think you can try this:
Let's start with the fact that this thread is nearly a year old. :icon_rolleyes:

>main()
While this will still work, as C99 compilers become more prevalent your code will quickly become a liability as C99 removed the implicit int feature. Now you must specify a return type. You can return any type you want, as long as it's int.

>printf ("Enter a really large number: ");
It's a good idea to add an fflush call for stdout so that this prompt is visible before fscanf starts blocking for input.

>char *no;
>fscanf (stdin, "%s[0-9,]", &no);
Use of an uninitialized pointer is the height of stupidity. I don't care what compiler options you use, this code is wrong.

>free (no);
I'm shocked that you managed to compile and run your code without any problems. Trying to free a pointer that wasn't returned by malloc (or calloc, or realloc) is extremely likely to fail miserably.

>Note this will not take floating point, you need to makeup
>the string such that it takes the floating point number.
Which isn't possible, as the valid formatting for a floating-point number is unsurprisingly complex. You can't boil all of the rules down to a single scanf format string and expect it to cover all of the valid cases while still disallowing all of the invalid cases.

Narue 5,707 Bad Cop Team Colleague

Good job, Rammohan from Banalore! Your m4d sk1llz as a Technical lead in a big IT firm have helped you answer a trivial question over a year after the rest of us with code that would have worked beautifully fifteen years ago but would fail to compile on at least one very widely used modern compiler. :icon_rolleyes:

Narue 5,707 Bad Cop Team Colleague

>So is the conversion operator not considered overloading the () operator whereas the
>function call operator is considered overloading the () operator, both are considered
>overloading the () operator, or neither are considered overloading the () operator?
The function call operator and operator() are the same thing. Here's how you can break it down, and it depends on what goes after the operator keyword:

T operator() ( ... )
{
  ...
}

This is overloading the () operator because the operator you want to overload follows the operator keyword (operator()). Notice the seemingly redundant parameter lists, which is a good sign that the () operator is being overloaded.

operator T()
{
  ...
}

This is overloading the implicit conversion operator to type T because the type T follows the operator keyword (operator T). A space is required between the two so that the construct isn't treated as an identifier. The () in that is the parameter list, not the operator to overload.

Your book is correct, but it sounds like it's trying to be too clever in the explanation and causing confusion.

Alex Edwards commented: Wow I honestly was unaware of the conversion overload O_O - whoo! Thank you! =) +3