Narue 5,707 Bad Cop Team Colleague

>It's hypnotizing effect causes painfull eyes and a significant decrease in concentration
If you find that hypnotic, don't watch the version with music. :D

John A commented: hahahahaha +15
WolfPack commented: I like the avatar. Don't care about what Joe says. +8
Narue 5,707 Bad Cop Team Colleague

>does anyone know if there is a code in c++ that allows print on paper instead of monitor?
Communicating with specific hardware is outside the bounds of standard C++. If you want a good answer, you need to tell us what compiler you're using and your operating system.

scream2ice commented: thnx +1
Narue 5,707 Bad Cop Team Colleague

>I wanted to know where will the selected message will be printed?
It's a part of the preprocessor, therefore it's a compile-time operation. Logically, you can expect the message to be printed in the compiler's output. In Visual Studio that's the output window (Ctrl+Alt+O).

>Can you give me a working example for it, and how it work...

#include <iostream>

#pragma message("This is a test")

int main()
{
  std::cout<<"Hello, world!\n";
}

This is in the output window (I've highlighted the message):

1>------ Build started: Project: Test, Configuration: Debug Win32 ------
1>Compiling...
1>main.cpp
1>This is a test
1>Build log was saved at "file://c:\C++ Projects\Test\Test\Debug\BuildLog.htm"
1>Test - 0 error(s), 0 warning(s)
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
Alex Edwards commented: That was a great example, I'll have to study the #pragma directive too +1
Narue 5,707 Bad Cop Team Colleague

>Try--
>srand( time(NULL) );
How is that supposed to fix the incompatibility of time's return value with srand's parameter? By the way, 0 and NULL are identical in C++.

>try using time without ctime
Then the declaration would be missing.

>ctime has a function called time_t time ( time_t * timer )
>which most likely masks the time function defined in std
It's generally a bad idea to talk about things unless you have a clue. Seriously, I can't imagine where you pulled that explanation from.

Here's the real problem. time(0) returns a value of type time_t. srand takes a parameter of type unsigned int. The warning is saying that for the OP's compiler, time_t is a larger integral type than unsigned int and converting from the larger type to the smaller type may affect the value.

The easy solution is to use a cast to explicitly tell the compiler you know what you're doing and to shut the hell up:

srand ( (unsigned)time ( 0 ) );

But because of standard restrictions on time_t, you can't be sure that this will work in all cases (though I don't know of any systems where it will fail). The 100% correct solution is not to use time_t directly, but rather a hash of the value for seeding rand:

#include <climits>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <limits>

unsigned hash_time()
{
  time_t now = time ( 0 );
  unsigned char …
Narue 5,707 Bad Cop Team Colleague

Every function parameter is passed by value in C. Pass by value means that a copy of the value is made and you access the copy from within the function. For example:

#include <stdio.h>

void foo ( int bar )
{
  printf ( "%p\n", (void*)&bar );
}

int main ( void )
{
  int bar;

  printf ( "%p\n", (void*)&bar );
  foo ( bar );

  return 0;
}

The addresses are different. You can simulate the effect of passing by reference (that is, passing an alias for the actual object) with pointers, but pointers are still passed by value:

#include <stdio.h>

void foo ( int *bar )
{
  printf ( "%p\n", (void*)&bar );
}

int main ( void )
{
  int *bar;

  printf ( "%p\n", (void*)&bar );
  foo ( bar );

  return 0;
}

bar is a pointer, but the addresses are still different. That's because the bar from main and the bar from foo are two separate entities. At this point you have enough information to understand what's wrong in your code.

What happens is you pass a copy of the pointer to doSomething and then assign to the copy, but the original is still unchanged. The solution when you want to pass by reference is to simulate it with a pointer, even if the original object is already a pointer:

#include <stdio.h>

void doSomething ( char **string )
{
  *string = "some string";
}

int main ( void )
{
  char *origString = NULL;

  doSomething …
Ancient Dragon commented: Great explaination :) +31
Narue 5,707 Bad Cop Team Colleague

>we did not have the right team in place to answer customer inquiries.
Translation: "We hadn't yet hired someone to troll the web looking for threads discussing our company." :icon_rolleyes:

Salem commented: LOL +17
Narue 5,707 Bad Cop Team Colleague

[Note: It's extremely rude to post a message and then edit it into nothing. I've kept my reply the same as if you hadn't removed post #5's previous content]

>it s that i hav made some code
If you ask for generic help without posting code, everyone will assume you want freebies. Daniweb is about sharing knowledge, not giving away custom homework solutions.

>but its pretty long
Long is subjective. To me a few thousand lines isn't a big deal, but to many beginners any more than 50 is long. A few hundred lines isn't a problem, and if your game is longer than that, you've overcomplicated or over engineered the program.

>no one helps me but make fun of me
Welcome to the real world.

>they say try it yourself ,it will increase ur knowledge confidence and blah blah....
They're right.

>pls don't give me lectures as I am already under much pressure.....
We generally don't take kindly to people who wait until the last minute to do their projects and then come running to us with vague pleas for assistance. If you get a lecture, you probably deserved it.

Narue 5,707 Bad Cop Team Colleague

>...And of course he has waited to the last minute so he needs it asap
Well, that's his problem, not ours.

Note that these answers assume that by "game developer", you mean a programmer rather than a graphic designer or one of the many other roles involved in creating a game.

>1. What would best prepare me for making a video game?
Professional games tend to ride the edge of hardware technology, so you should be very familiar (not to mention up to date) with computer hardware, especially graphics hardware, and how to interface with it. In my experience, game programmers are among the more talented programmers, so you should also have a strong foundation in programming theory and practice as well as the drive to compete in the industry.

>2. How long have you been working with video game making and designing?
I don't work in the game industry, nor is it a hobby. My focus is on developer tools and compilers, but I've consulted for professional game projects in the past on back-end code.

>3. What program is used to make a video game on the computer? Programs?
No single program is used, but you can expect a good development IDE, usually a 3D or 2D graphics package and a sound manager.

>4. How many steps are there in making or designing a video game?
Pretty much the same steps as any other end user software.

>5. …

majestic0110 commented: Better answers than mine :) +3
Narue 5,707 Bad Cop Team Colleague

You need to add the appropriate DLL as a reference. You can do that from the UI by right clicking on your project and choosing "References". From there you can add a new reference for .NET. Alternatively you can reference the DLL directly from your code with a #using statement:

#using <mscorlib.dll>

using namespace System;

int main()
{
  Console::WriteLine ( "Hello, world!" );
}
VernonDozier commented: This fixed the problem. +2
Narue 5,707 Bad Cop Team Colleague

>can anyone tell me if global variables are not liked
Experienced programmers tend to cringe when they see global variables.

>and why
Global variables are almost always an indication of poor design. They're such a small and innocent seeming thing, but the repercussions can be truly frightening if you know what to look for.

A good analogy for global variables is throwing a stone into a pool of water. You throw the stone in the pool and it makes a little splash. Then there are ripples all the way to the edges of the pool. Then the stone wedges itself in a submerged gas vent that builds up pressure for several days and explodes spectacularly, causing untold pain and chaos. ;)

jephthah commented: LOL :) +2
Narue 5,707 Bad Cop Team Colleague

>As in selecting which line to start from.?
Sure, but unless the file is structured enough to seek, you'll have to actually read your way to the correct line. Writing is harder if you mean to insert rather than overwrite. In that case you need to save the subsequent lines and shift them over like you would insert into an array.

CodeBoy101 commented: somewhat helpful +1
Narue 5,707 Bad Cop Team Colleague

>Pls help me in finding hcf and lcm of 2 nos
It's easy. All you do is grab the igm, do a qp on the xt half of the pgid and roll everything up into a qt7-qualified czsm. Hope that helps! :)

hammerhead commented: Helped me lol +2
Narue 5,707 Bad Cop Team Colleague

Note that there's a point at which it's a bad idea to change your name. When joey did it recently, it threw all of us off, and I'm still not used to calling him John A. :icon_rolleyes:

John A commented: Stop whining. You should be happy they both start with a 'J'. :) +15
Narue 5,707 Bad Cop Team Colleague

If I understand your question correctly, you want to return a reference to one of the structure instances inside your object:

#include <iostream>

struct block {
  int data;
};

class block_collection {
  static const int _size = 10;

  block _base[_size];
public:
  int get_size() const { return _size; }
  block& get_block ( int i ) { return _base[i]; }
};

int main()
{
  block_collection blocks;

  for ( int i = 0; i < blocks.get_size(); i++ )
    blocks.get_block ( i ).data = i;

  for ( int i = 0; i < blocks.get_size(); i++ )
    std::cout<< blocks.get_block ( i ).data <<'\n';
}
Run.[it] commented: Cheers again! +1
Narue 5,707 Bad Cop Team Colleague

Well, that's the same thing that you posted before. However, it's not a common variation of the "I want to make a triangle" crowd, which is why I suggested that the forum is messing up your careful formatting.

Narue 5,707 Bad Cop Team Colleague

>I would like to hear an explanation on why I can't do this.
Because you never told p where to point. Thus, it could point anywhere, and "anywhere" is very likely outside of your address space.

Google Spider commented: Coz she helped me with my dumb question* +1
Narue 5,707 Bad Cop Team Colleague

Hi, do it your damn self. We're not a homework service, but if you actually make an attempt, we'll be happy to help you along a little bit.

hammerhead commented: This post made me laugh :) +2
jephthah commented: i did a LOLercopter too +1
Narue 5,707 Bad Cop Team Colleague

1) You have several options. Here are a few:

  • Create your own case insensitive traits class and apply that to your strings.
  • Convert all of your strings to one case before doing comparisons.
  • Forget about the string specific search member functions and use STL-based searching where you can provide a predicate.

2) You need to check the boundaries of the match and make sure it's a character that you would classify as a word boundary (space, punctuation, etc...). But don't forget about hyphenated words.

bigbadowl commented: Really helpful - thank you +1
Narue 5,707 Bad Cop Team Colleague

>Would you mind to elaborate in what way this would be overkill?
Gladly. I misread your post.

>here's the simple answer:
In this case I'd say that simplicity isn't worth it. You're teaching bad habits again.

>of course that doesn't even begin to address error checking.
Indeed. You make several assumptions about your data:

1) You assume that argv[1] exists.
2) You assume that argv[1] is not a null pointer.
3) You assume that argv[1] represents a valid integer.

Simple or not, those assumptions make your code severely broken because you simply can't control the data sent to your program from an outside source. At the very least you need to correct those three things:

int main ( int argc, char *argv[] )
{
  /* Make sure argv[1] exists and is not null */
  if ( argc > 1 ) {
    /* Make sure argv[1] is a valid integer */
    if ( try_parse_int ( argv[1] ) ) {
      int value = atoi ( argv[1] );

      /* ... */
    }
  }

  return 0;
}

The problem with atoi is that it's literally impossible to error check it. The return value is the only guaranteed mechanism for determining an error, and the value that atoi returns on error could also be returned on success. Not to mention that if an integer can't hold the result, the behavior is undefined. So really the only way to use atoi safely is to write or …

jephthah commented: that's actually an awesomely instructive example. beginners mightn't understand it, but i like it a lot. +1
Narue 5,707 Bad Cop Team Colleague

>is there a way to build a website with C?
You can write CGI in C, if you really want to. But it's not really worth it as CGI tends to focus on the very thing that C is poor at: string manipulation.

Salem commented: Totally right. +15
Narue 5,707 Bad Cop Team Colleague

>is there a built in function to deal with numbers similar to how the swap member function
Yes, include <algorithm> and you can use the std::swap template function as AD has shown.

Narue 5,707 Bad Cop Team Colleague

>Thanks for the advice but I disagree.
You can disagree, but that doesn't change anything. You need to learn how to program first, then you can delve into the niches of languages, find out where you want to be, and learn the languages that take you there. Your lack of experience is causing you to make another mistake, which is thinking that learning a language unrelated to what you want to do is a waste of time.

majestic0110 commented: you're always right! +2
Narue 5,707 Bad Cop Team Colleague

A few tips:

>printf("File Open Error %s", filename);
>exit(0);
Most likely you don't want to use stdout for your error messages. At the very least use stderr, and for more robust messaging, use your own stream. Either way you'll be using fprintf. Also, 0 means success, so exit(0) is functionally identical to return 0 . For portability purposes you should be using EXIT_FAILURE. Ideally you would have something like this:

errno = 0;
fptr = fopen ( filename, mode );

if ( fptr == NULL ) {
  fprintf ( stderr, "Unable to open [%s]: '%s'\n",
    filename, strerror ( errno ) );
  exit ( EXIT_FAILURE );
}

Though I still tend to frown on hard termination for all but the most extreme of errors. You could easily get the user to enter an alternative filename.

>fgets (buf, 90, fptr);
Always check your input calls for success.

>printf("%s (%p)\n",buf,fptr);
The %p specifier expects a pointer to void. Just because fptr is a pointer doesn't mean it's the correct type. Avoid undefined behavior with a cast:

printf ( "%s (%p)\n", buf, (void*)fptr );

>for (inx=0; inx<strlen(MTDF_Header.Duration); inx++)
This effectively turns an O(N) loop into an O(N*M) loop. Unless MTDF_Header.Duration changes length in the body of the loop, don't use strlen in your condition. This also serves to make your lines shorter (a big help if you use wide indentation):

size_t len = strlen ( MTDF_Header.Duration );

for ( inx = 0; inx …
jephthah commented: i appreciate the time you took here. good advice :) +1
Narue 5,707 Bad Cop Team Colleague

The question is one of indentation, not embedded tabs. You only have to worry about the consecutive tabs at the beginning of a line:

$post_data =~ s/\n(\t+)/' ' x (tab_stop * length($1))/e;

Where post_data is your string and tab_stop is the number of desired spaces to replace tabs with.

Narue 5,707 Bad Cop Team Colleague

>Sorry to hear that.
I'm not. We can easily do without people like that.

VernonDozier commented: Amen. +2
Narue 5,707 Bad Cop Team Colleague

The filename parameter has to be a C-style string:

ifstream myfile1 (path1.c_str(), ios::binary);
ofstream myfile3  (path2.c_str(), ios::binary);
kartouss commented: Very Helpful +1
Narue 5,707 Bad Cop Team Colleague

Salem

I get the impression that he doesn't particularly like me (or anyone, really), but we've been together on programming forums for several years. Salem is the programming bot, because he's always right (I can count the times I've corrected him on one hand, and they were minor points) and seems to have experience with everything. Sometimes he has a short fuse, but he keeps it in check most of the time. As an ex-moderator, he spends a lot of time reporting posts that fail to use code tags. I guess that's his pet peeve. ;)

Salem is on the list of programmers who make me look like a rank beginner.

Narue 5,707 Bad Cop Team Colleague

~s.o.s~

My anime buddy, sos is very knowledgeable and helpful on the software development forums. He's one of the few programmers who has earned my respect through repeated accuracy and proof of ability. sos is another moderator that I tend to rely too much on due to his awesome judgment and reliability. As a regular member, a programmer, and a moderator, this guy is definitely a role model and fits well as a mentor.

~s.o.s~ commented: Thank you so much, I wonder how I missed this thread. :) +0
Narue 5,707 Bad Cop Team Colleague

>why the f would anyone think this is a reasonable question for a programming class?
I've concluded that people who don't know anything substantial use trivia as a replacement for expertise. Teachers have an uncanny tendency to fit that description. Some forum goers do as well, but in a different way. For example, people who actually help solve problems here have at least some measure of my respect, even if they're wrong. It's much more difficult to learn how to program than it is to regurgitate what you read in a book. But people who focus only on bitching about stuff like void main, fflush(stdin), goto, and bracing styles strike me as posers.

WolfPack commented: Well said. +7
Narue 5,707 Bad Cop Team Colleague

>Any reason why this wouldn't fix it?
I add warning 4996 to my "I don't give a crap" list in the project settings[1]. You can also disable it directly in the code using a pragma:

#pragma warning(disable:4996)

[1] Assuming you're using Visual Studio, of course. ;)

Narue 5,707 Bad Cop Team Colleague

Regular: A Daniweb member who visits/posts frequently, and tends to be friends with others who visit/post frequently.

New members could easily be overwhelmed by the mass of people running around, and it's hard to fit yourself in a community as old as Daniweb, where members are already well entrenched and have formed cliques. To make this inclusion easier, I had the idea of introducing those people who are around a lot and well known in the community.

This way new (and not so new) members can see who the big names are, why they're big names, and get a little background in the history of Daniweb. A little inside knowledge goes a long way toward fitting in. :)

So here are the rules:

1) You're not allowed to introduce yourself.

2) You're not allowed to bash someone for an introduction you don't agree with.

3) You're allowed to add to an introduction. For example, if someone introduces Dani and forgets to mention that she's a hopeless work-a-holic, you're welcome to add that to partial introduction.

4) You're encouraged to be honest. I'm well aware that some members aren't popular, so there's no need to pretend otherwise. We want the new guys to get a realistic idea of Daniweb. Hopefully everyone can be professional enough not to get into fights because of a harsh introduction. :icon_rolleyes:

I'll start.

Ancient Dragon

AD is in the informal clique of guru programmers for the …

Dani commented: I rarely hand out rep but this is an awesome thread. Thanks so much for starting it! +32
Narue 5,707 Bad Cop Team Colleague

This covers several different trees, including a variation of the heap. I haven't yet gotten around to finishing my splay tree tutorial, but here's a draft of the code (for both top down and bottom up splaying):

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

struct jsw_node {
  int data;
  struct jsw_node *link[2];
};

struct jsw_tree {
  struct jsw_node *root;
};

struct jsw_node *jsw_single ( struct jsw_node *root, int dir )
{
  struct jsw_node *save = root->link[dir];

  root->link[dir] = save->link[!dir];
  save->link[!dir] = root;

  return save;
}

struct jsw_node *jsw_splay_r ( struct jsw_node *root, int *key )
{
  if ( root != NULL && *key != root->data ) {
    int dir = root->data < *key;

    root->link[dir] = jsw_splay_r ( root->link[dir], key );

    if ( root->link[dir] != NULL ) {
      struct jsw_node *zig = root->link[dir]->link[dir];
      struct jsw_node *zag = root->link[dir]->link[!dir];

      if ( zig != NULL && *key == zig->data ) {
        /* Zig-Zig */
        root = jsw_single ( root, dir );
        root = jsw_single ( root, dir );
      }
      else if ( zag != NULL && *key == zag->data ) {
        /* Zig-Zag */
        root->link[dir] = jsw_single ( root->link[dir], !dir );
        root = jsw_single ( root, dir );
      }
    }
    else
      *key = root->data;
  }

  return root;
}

struct jsw_node *jsw_busplay ( struct jsw_node *root, int key )
{
  int dir;

  root = jsw_splay_r ( root, &key );

  dir = root->data < key;

  /* Final Zig if necessary */
  if ( root->link[dir] != NULL && key != root->data )
    root = …
Narue 5,707 Bad Cop Team Colleague
while (!inStream.eof()) {
  L1.append(temp);
  inStream >> temp;
}

You append temp before ever reading anything. That's one of two good reasons not to use eof() as a loop condition. The other reason is that you can get an off-by-one error and process the last item in the file twice. This is shorter and works better:

while ( inStream>> temp )
  L1.append ( temp );
darklich13 commented: Thanks for the help again!! +1
Narue 5,707 Bad Cop Team Colleague

Reverse your order of opening. Open the main form (but don't show it). Then from the main form's load event open the login form. If the login is valid, show the main form and close the login form. If the login is invalid, do an Application.Exit() or close the main form.

What's happening right now is that the login form is your main form as far as .NET is concerned because it's the first form opened. When the main form closes, the application terminates.

Narue 5,707 Bad Cop Team Colleague

>I'm concerned that the number I arrive at will scare
>off my client from future development opportunities
I worried about that at first, but custom software is expensive, and quality custom software is more expensive still. You need to stick to your guns on the base price[1], or they'll end up taking advantage of you. Here are two reasonable arguments for defending your price that any reasonable client will respect:

Clients should be aware that if they want someone to write an application just for them, according to their specific needs, they're going to pay more than if they bought a "close enough" package at retail prices. This is the balance of value for cost; custom software is vastly more valuable because it does exactly what the client needs.

Another factor is the the number of clients you can reasonably sell this application to. If you can't productize it for some reason, or have no plans to sell the same or a similar solution to other clients, you can't compete with software houses that have hundreds or thousands of buyers. To make a profit, your price goes up if the project is to be worth your time. Clients should be aware of this as well.

If your price is fair, your concerns are unfounded.

[1] For repeat clients with which you have a good relationship, discounts and generous support contracts are an excellent way to keep their business.

jephthah commented: interesting +1
Narue 5,707 Bad Cop Team Colleague

>Please correct me if my understanding is not correct
It sounds good to me.

Narue 5,707 Bad Cop Team Colleague

>when I close the dialog, the instance of that Form2 form does not exists anymore
Not quite. Here's a common idiom that I see and use for dialogs:

MyDialog dlg = new MyDialog();

if ( dlg.ShowDialog() == DialogResult.OK ) {
  // Filling a text box, for this example
  this.textBox1.Text = dlg.ResultText;
}

ResultText would be a public property for the dialog:

internal class MyDialog: Form {
  private string _resultText;

  //...

  public string ResultText {
    get { return _resultText; }
    private set { _resultText = value; }
  }

  //...
}

Another way to communicate between forms is events, but with dialog forms that's usually overkill.

Narue 5,707 Bad Cop Team Colleague

Wow, I was just explaining interfaces to a coworker the other day. Freaky.

>Does any one know a robust benefit of using interfaces?
Consider the concept of data hiding. Let's say you want to provide a class to some client code, but don't want to give them full access. One way to restrict access without limiting the functionality of your class is to implement an interface and require the client code to get objects through a factory:

using System;

namespace JSW {
	public class Program {
		static void Main() {
			IFoo myfoo = FooFactory.GetFoo();
			Bar mybar = new Bar();

			myfoo.Print();
			mybar.Print();
			mybar.Test();
		}
	}

	// Restricted type for clients
	public interface IFoo {
		void Print();
	}

	// Factory for clients
	public class FooFactory {
		public static IFoo GetFoo() {
			return new Bar();
		}
	}

	// Fully functional type for us
	internal class Bar: IFoo {
		public void Print() {
			Console.WriteLine( "Foo!" );
		}

		public void Test() {
			Console.WriteLine( "Test" );
		}
	}
}

This is especially useful when interfacing with COM.

Another benefit of interfaces is team development. If you have a dozen programmers working on different pieces of code that need to connect, it's best to define interfaces for the connections. As long as the programmers write according to the interfaces, everything will link together nicely regardless of personal choices and style.

Yet another benefit is that with interfaces you can use a class without having defined it first. For example, if you have …

Narue 5,707 Bad Cop Team Colleague

Nope, you can store strings however you want. I've seen people use linked lists before, for example. And to support broader character sets, you're not restricted to the char type either. However, the de facto standard string is an array of char/wchar_t or an object of basic_string<char>/basic_string<wchar_t>.

Narue 5,707 Bad Cop Team Colleague

First, your code shouldn't compile because fibArr tries to use implicit int for the return value, which is illegal C++. Second, you don't even try to print the result of fibNum. Third, you should release the memory you allocate in fibArr. Finally, and this is the biggest error, you're not properly setting num, which is causing fibArr to seg fault. You're not even really using that data member, so you might as well just get rid of it:

#include <iostream>
using namespace std;

class fibonacci
{
public:
	long fibNum( int n );
	void fibArr( int n );
};
//============================
long fibonacci::fibNum(int n)
{
	if (n<0) { return 0; }
	if (n<2) { return n; }
	else { return fibNum(n-1) + fibNum(n-2); }
}
//============================
void fibonacci::fibArr(int n)
{
	int *Arr;
	Arr=new int[n];

	for (int i=0; i<n; i++)
	{ 
		Arr[i]=fibNum(i);
		cout<< Arr[i] << " ";
	}
}
//============================
int main()
{
	fibonacci fibo;

	cout<< fibo.fibNum ( 10 ) <<'\n';
	fibo.fibArr ( 10 );

	return 0;
}
Narue 5,707 Bad Cop Team Colleague

>I wonder though if there coulde be any good sites on how to begin writing
>an interpreter on the internet for just C++. A really beginner guide perheps.
The two most complicated pieces of software you can write would probably be an operating system and a C++ compiler. Just to give you an idea of the water you're trying to jump into.

Your first step should be to severely limit the expressions you want to support. Then grab the relevant grammar from the C++ grammar, and come up with a parsing scheme. If your grammar is simple enough, you can use a straightforward state machine or stack based parser parser. Both of those are relatively easy to understand and accessible to beginners.

A good introduction to language parsing would be writing a calculator that supports infix notation. Another is a boolean expression evaluator.

scru commented: Thank you! I've been dying for something to code lately. I'm going to get on that calculator! +3
Narue 5,707 Bad Cop Team Colleague

>i wud like u to tell me if its good to use system('cls')
No, it's a big security risk, and the system function is painfully slow.

>or shall i create a loop of '\n' so that it will jst bring a new screen in front of me...???
This is your most portable option, but you can't tell how many newlines to print, and the cursor will be at the bottom of the screen rather than the top as it would be in a true screen clear.

>any other more feasible option is welcome.
Here's a solution that's portable across Windows, but it won't work on other operating systems without emulation:

#include <windows.h>

void clear_screen()
{
  DWORD n;                         /* Number of characters written */
  DWORD size;                      /* number of visible characters */
  COORD coord = {0};               /* Top left screen position */
  CONSOLE_SCREEN_BUFFER_INFO csbi;

  /* Get a handle to the console */
  HANDLE h = GetStdHandle ( STD_OUTPUT_HANDLE );

  GetConsoleScreenBufferInfo ( h, &csbi );

  /* Find the number of characters to overwrite */
  size = csbi.dwSize.X * csbi.dwSize.Y;

  /* Overwrite the screen buffer with whitespace */
  FillConsoleOutputCharacter ( h, TEXT ( ' ' ), size, coord, &n );
  GetConsoleScreenBufferInfo ( h, &csbi );
  FillConsoleOutputAttribute ( h, csbi.wAttributes, size, coord, &n );

  /* Reset the cursor to the top left position */
  SetConsoleCursorPosition ( h, coord );
}
aashishsatya commented: Narue is awesome! +0
Narue 5,707 Bad Cop Team Colleague

Programmers are always confused. It's a fact of life. So start at the top and go one error at a time. Often one error will cause others, and the cascade effect overwhelms you. So don't treat it as 44 errors and 1 warning that you don't understand, treat it as

dynarray.h(28) : error C2061: syntax error : identifier 'itemType'

Ask yourself, "what is itemType?", and "why wouldn't my compiler recognize it?".

mitrmkar commented: A good piece of advise, should (somehow) be made clear to all the beginners +1
Narue 5,707 Bad Cop Team Colleague

>how can one find the upper limit of an array?
Assuming the upper limit in terms of capacity, you can use the Length property. my_array.Length gives you the number of items the array can hold, and my_array.Length - 1 gives you the last valid index.

>ow can one change that upper limit?
Rebind the reference to a new array:

using System;

namespace JSW {
  class Program {
    static void Main() {
      int[] my_array = new int[5];

      Console.WriteLine( "Size: {0} -- Last: {1}",
        my_array.Length, my_array.Length - 1 );

      my_array = new int[10];

      Console.WriteLine( "Size: {0} -- Last: {1}",
        my_array.Length, my_array.Length - 1 );
    }
  }
}

The size of an array is locked down when you create the object. If you want an array that can be resized, you use a List<T> object (or an ArrayList prior to .NET 2.0), or some other suitable collection.

majestic0110 commented: Thank you, good explanation +1
Narue 5,707 Bad Cop Team Colleague
Lardmeister commented: nice help +2
Narue 5,707 Bad Cop Team Colleague

Life isn't fair. Personally, I'm wondering why you chose CEOs to bash for making obscene amounts of money and not professional athletes or actors.

majestic0110 commented: totally agree! +1
Narue 5,707 Bad Cop Team Colleague

>are we still here?
Yes, and apparently we'll stay here for as long as it takes everyone to understand the point of scanf.

>I would be run out of the plant if i tried to pass
> a program to the assembly line that used <snip scanf code>
I have a similar practice in the real world (I work for a C and C++ compiler vendor): don't use scanf unless you wrote it. That works out well because only a handful of our programmers have touched the scanf source, and they're the ones who can be trusted to use it properly. ;)

>please put all the "error checking" you like and then tell me how the input:
>$12.34
>works out for you.
It works just peachy. I even took it to the next level and accepted negative currency values as they would appear on a ledger:

#include <stdio.h>

#define POSITIVE_LEAD "$" /* Leading char for positive currency */
#define NEGATIVE_LEAD "(" /* Leading char for negative currency */

#define length(a) ( sizeof (a) / sizeof *(a) )

int main ( void )
{
  const char *currency_fmt[] = {
    "%[" POSITIVE_LEAD "]%f",   /* Currency format (positive) */
    "%[" NEGATIVE_LEAD "]$%f)", /* Currency format (negative) */
  };

  char lead = EOF;
  float value;
  int i;

  /* Try to read an expected currency format */
  for ( i = 0; i < length ( currency_fmt ); i++ ) {
    if ( scanf ( currency_fmt[i], …
jephthah commented: zing +1
Dave Sinkula commented: +Rep is probably long overdue, but this is a scanf discussion, so it now becomes imperative. +13
Narue 5,707 Bad Cop Team Colleague

>What is the use of using namespace std; ?
Namespaces are like drawers in a filing cabinet. All of the standard library is in one drawer, and the only way to get to the stuff in that drawer is to tell C++ where to find it. You do that by prefixing the name with std:

#include <iostream>

int main()
{
  std::cout<<"Hello, world!\n";
}

std::cout is basically like saying "Hey C++! Look in std and get me cout , asap!". If you don't tell C++ which drawer to look in, it won't find what you want. That's why this gives you a nasty little error, C++ is complaining that it can't find cout:

#include <iostream>

int main()
{
  cout<<"Hello, world!\n";
}

Now, it's somewhat tedious to keep typing std:: in front of everything, so you can also tell C++ to assume what drawer to look in. A using declaration tells C++ to assume that the declared name is in the declared namespace:

#include <iostream>

int main()
{
  using std::cout;

  cout<<"Hello, world!\n";
}

The using std::cout part tells C++ to assume that wherever you say cout , you really mean std::cout .

Even that can get tedious, and maybe you want to say "Hey C++! Pretend that everything is prefixed with std:: ! On the double!" You can do that with a using directive:

#include <iostream>

int main()
{
  using namespace std;

  cout<<"Hello, world!\n";
}

The using namespace std part is a quick and easy way …

vmanes commented: Nicely stated. +2
Narue 5,707 Bad Cop Team Colleague

>Sorry but you did not get the message Narue .
Don't apologize, restate your question so that somebody understands what you want.

jbennet commented: :) your answer was perfect +24
Narue 5,707 Bad Cop Team Colleague

I've looked through your posts, The Dude, and determined that a certain measure of harassment through the reputation system has violated Keep It Pleasant. The parties involved have been dealt with accordingly.

If you could send me a list of the posts that have rep you feel was part of this attack, I'll see about getting the points and comments removed.

On a side note, if anybody feels any reputation has broken the rules, please report the post where the reputation was given, and make it clear that the reason the post was reported is due to rep[1]. That way the mods can make a decision quickly and nip things like this before they turn into a big deal.

[1] Otherwise we'll look at the post itself, which would be counter-productive.

Finally, this thread is getting a little hot and going nowhere, so I'm closing it.

joshSCH commented: heh.. you're right, it was harassment. :P +12
~s.o.s~ commented: Wha...and what about our opinions? Drats! ;-) +20