Narue 5,707 Bad Cop Team Colleague

>i dunno wat is dev-c++ so better u tell me abt it..
How about you just google it like the rest of the civilized world?

>n y is c++ a dead compiler s we r bein taught c++ on the turbo compiler...
Turbo C++ is an old compiler that was released before the current C++ standard. As such, you can't write proper C++ with it. If you're learning C++ on Turbo C++, you're screwing yourself because you'll have to unlearn half of what you're learning now, then learn the tons of new concepts and features of modern C++ when you realize that you never really learned C++ in the first place.

>so well wat is d problem with the getchar s u said it in the reply..
I was referring to the name. getchar suggests that it returns a char when it really returns an int. This causes a lot of people (including at least one notable author) to fall into the trap of infinite loops caused by EOF (a negative quantity) being returned from getchar but saved to a char when char is unsigned.

By the way, not everyone is a native English speaker, and your childish abbreviations and poor grammar would make your posts virtually impossible to understand. Not to mention that it greatly diminishes anyone's opinion of your intelligence and abilities. Unfair, yes. But that's how it works, and when you put effort into proper spelling and grammar, people are more …

Narue 5,707 Bad Cop Team Colleague

>Compiler used by me is turbo c
Turbo C is neither a C++ compiler, nor new enough to know what the C++ standard even is. Get something that isn't a complete dinosaur, like Dev-C++. There's no point in trying to learn C++ on a dead compiler; it'll just frustrate you.

Narue 5,707 Bad Cop Team Colleague

>transform(myString.begin(),myString.end(),myString.begin(),toupper);
Amazingly enough, that's correct, but I'm not sure if it's correct because you intended it to be or if it's correct because you messed up your headers. I don't recommend using toupper directly with transform because most programs will want to use the toupper declared in <cctype>, but will also include <iostream>, which declares another form of toupper. This causes an ambiguity and the code will mysteriously fail to work. The best fix is to write a wrapper around the toupper that you want:

struct upper {
  int operator() ( int c )
  {
    return toupper ( static_cast<unsigned char> ( c ) );
  }
};

transform(myString.begin(),myString.end(),myString.begin(),upper());
Narue 5,707 Bad Cop Team Colleague

>could you elaborate
I'd be happy to elaborate. jwenting was saying to RTFM. If that doesn't work, tell us what compiler you're using and we'll tell you how to get an executable file out of it.

Narue 5,707 Bad Cop Team Colleague

>Could you tell me a reason why this is happening?
name and acc_type are uninitialized pointers in main. You're trying to write to memory that you don't own, and the compiler seems to think that's a bad idea. :rolleyes:

Narue 5,707 Bad Cop Team Colleague

It sounds like you have a building issue rather than a code issue. It links and runs just fine for me on Visual Studio .NET 2003. Try making a new project and pasting your code into it, then let us know if it worked or not.

Narue 5,707 Bad Cop Team Colleague

>Why not write a Python program to translate C++ code to Python code?
Probably (barring sneaky tricks that wouldn't count) because you'd effectively be writing both a C++ and Python parser and evaluator, not to mention a kickass AI to convert C++ into intelligent Python. Doable, but very very difficult to the point of not being worth the effort.

Narue 5,707 Bad Cop Team Colleague

>I asked some of our friends in the C/C++ Forum at DaniWeb
Who gave you the answer you asked for but not the answer you were looking for. C's nesting limit has nothing to do with Python's nesting limit. But the cold hard fact of the matter is that Python limits static nesting to 20 levels. Break that ugly ass mess of loops up into a few functions with more reasonable nesting.

Narue 5,707 Bad Cop Team Colleague

>Does anybody know the limit of nested for loops in C or C++?
15 levels in C89, 127 levels in C99 and 256 in C++ are the minimum limits. Any decent compiler should take the standard's advice and not impose arbitrary limits, so if you hit pretty much any implementation limit then either you're an awful programmer, you're trying to hit a limit, your compiler probably sucks, or your automated code generator has a bug. ;)

>If there is a limit, what is the reason?
The standard has to guarantee that certain programs will work. As such, it needs to set minimum limits on a lot of things to ensure that those programs will work. An implementation is free to increase the limits, but required to support the minimum levels.

>The problem came from Python that seems to balk at more then twenty levels of nesting.
But it has nothing to do with limits in C. Python developers made an active choice to limit static nesting to 20 levels for performance reasons. If you want more nesting, Python allows non-static nesting where you have nested loops, then a function with nested loops as the inner operation.

Narue 5,707 Bad Cop Team Colleague

>Can someone tell me why this happens
Sure. Since you're working with a pointer to an array, you need to dereference the pointer first before you start trying to index the array. When you say *myarray[j], you're doing the indirection in the wrong order, with [j] first, then * because array indexing binds more tightly than indirection.

So the question is, why are the first 4 numbers correct when the rest ar obviously out of bounds array indexes? Let's say that the size of a pointer to an array of short is 4 bytes and a short is 2 bytes. myarray[0][0] is the same as *myarray, so you have a pointer to the first element, which when dereferenced gives you the first element.

Then j is incremented so you're looking at myarray[0][1], but since you're indexing a pointer to an array rather than the array that the pointer points to, you're actually at myarray[1][0], and dereferencing that pointer gives you the fifth element. Repeat the process and *myarray[0][2] is actually *myarray[2][0], which gives you the ninth element, and *myarray[0][3] is actually *myarray[3][0] which gives you the thirteenth element.

Then all hell breaks loose because you move to the first element of the next array, but since there isn't one, you're out of bounds and should expect nothing less than improper behavior.

>cin.ignore(cin.rdbuf()->in_avail() + 1);
As a side note, this isn't portable. in_avail() tells you how many characters are known to be available in the …

Narue 5,707 Bad Cop Team Colleague

Okay, let's make some observations on the goto code:

Y:  A
     B
     if a GOTO X
     C
     if b GOTO Y
X:  D

First, Y is always executed at least once because the test to GOTO Y is at the end of the "block". That suggests a loop that tests the condition at the end rather than at the beginning, so we'll throw in a do..while for Y (# denotes a comment):

#Y:
DO
  A
  B
  if a GOTO X
  C
WHILE b
X: D

If you're not allowed to use a special loop like that in your pseudocode, then you have the right of it in setting a flag to a successful condition for the first iteration.

GOTO X is a classic break from the loop, so if your pseudocode can support it, that's the easiest way:

#Y:
DO
  A
  B
  if a BREAK
  C
WHILE b
D

However, even though that's likely the solution that you would take in real code, BREAK is akin to GOTO in that it makes an unconditional jump, so it might not be an acceptable solution in this case. The alternative is what you did, to use flags to drive the loop:

#Y:
done = false
DO
  A
  B
  if a done = true
  C
WHILE b AND done <> true
D

All in all, this saves you a potentially confusing conditional branch inside the loop. But your solution is still correct. :)

Narue 5,707 Bad Cop Team Colleague

>will I be able to learn everything I need to know about computer
>programming in terms of web development and software
>development with a computer science degree?
Bwahahahahahahaha! No course will teach you everything you need to know. Everyone I've worked with who has a degree says that they use only a small fraction of what they learned, and the majority of what matters to them they learned on their own. If you're expecting the classes to teach you everything you need then you might not have the right mindset to be a successful developer. A degree is usually nothing more than a piece of paper to get you your first job.

That said, CS will open your eyes to a lot of things that you may not have considered. Those perspectives might make you a better problem solver in the real world.

Narue 5,707 Bad Cop Team Colleague

>should I go into software engineering or computer science?
What courses does your school offer, because most of the time the closest you'll get to a software engineering course is CS. Everything else typically focuses more on electrical engineering, business, and management.

Narue 5,707 Bad Cop Team Colleague

My specialty is systems programming, and my job is the lead engineer in software research and development.

Narue 5,707 Bad Cop Team Colleague

Computer science is probably your best bet for a major that a lot of employers are familiar with and will help with further education. If your school has an undergraduate software engineering major then that will probably focus more on the implementation side rather than the theory of CS, but software engineering usually results in an associate's degree rather than a bachelor's, which is a minimum for most companies to hire a developer.

>if you could give me your location, degree in what major and how much money you make yearly
I live in Atlanta, Georgia. My only schooling in programming is an associate's from a local community college, and while I won't give you hard numbers, I make more than your minimum.

Narue 5,707 Bad Cop Team Colleague

>I would like to know which is better.
There's no difference if they both compile (they might not for user-defined types), pick which you find more intuitive.

>Real C++ people...?
I don't think I count as a real C++ person, but both call the primary (non-copy) constructor. The only noticeable difference would be if the constructor in question is defined as explicit, in which case an implicit argument would be illegal:

class test1 {
public:
  test1 ( int init ) {}
};

class test2 {
public:
  explicit test2 ( int init ) {}
};

int main()
{
  test1 a1 ( 0 );
  test1 b1 = 0;
  test2 a2 ( 0 );
  test2 b2 = 0; // This will cause an error
}
Narue 5,707 Bad Cop Team Colleague
Narue 5,707 Bad Cop Team Colleague

>thought i would find some sensible and helpful people here.. which now i realise was wrong
By "sensible and helpful" you mean you want people who will give you answers. That's the impression I got from your post, which was nothing more than saying "here are the questions, give me the answers, thanks". Don't mistake refusing to spoonfeed with not being helpful, kthxbye.

>And secondly if "people like me" don't ask questoins.. "people like you" don't have a place here
Then "people like me" will go do something else. I volunteer to help people, which means I'm not obligated to help you if I don't want to, and I have no reason to be here other than my desire to help.

>if you can't guide someone...
I'm more than willing. Just not with you until you prove that you're willing to learn and do some of your own work.

>with all the experience you "brag" about..
Now you're putting imaginary words in my mouth. Where did I brag about experience? Feel free to quote me if you can find anything. I let my answers do the talking about my qualifications. Words, as they say, have no value unless you can back them up with actions.

>your experience doesn't stand anywhere.
Well, my experience keeps me employed, and that's a great deal more important to me than some anonymous bozo on an online forum who doesn't "get it" and feels the need …

Narue 5,707 Bad Cop Team Colleague

>These are some of the few questions for which i couldn't find answers.
Clearly you didn't look very hard. Not only are these easy to figure out for just about anyone with some measure of experience, the answers are everywhere because people like you keep trying to get others to do your work on a regular basis.

Narue 5,707 Bad Cop Team Colleague

>problem is how to implement, say a linked list in Python, since it doesn't have
>pointers, or even static types so how this could be implemented is pretty unclear to me
Python is kind of screwy if you're used to a strongly typed language like C++ (or even C!). To make a node, create a class:

class node:
  def __init__ ( self, data = None, link = None ):
    self.data = data
    self.link = link
Narue 5,707 Bad Cop Team Colleague

>I read this complicated theory before. I downloaded Perl from
>their Web site and Java from Sun and Apache. I written and ran few examples also. Please explain.
What's there to explain? It's common sense. Do you go to the store and buy English? No, you buy books written using English. Likewise, you download software written using programming languages. But you don't download a programming language just like you don't go out and buy a spoken language. You downloaded the Perl interpreter, and the Java development kit, not the languages that they implement. In real world terms, you didn't go out and buy English, you bought a typewriter so that you could write English.

>There's clear understanding of HTML, JavaScript, JScript,
>RSS, Atom, JDK, Tomcat, Perl vendors to me ..
No, clearly there isn't or you wouldn't even be remotely confused.

>Who is Borland? Who is Turbo C++?
Borland is a company that sells a C++ compiler, Turbo C++ is one of those compilers sold by Borland. That's why it's called Borland Turbo C++. But that doesn't really matter because Turbo C++ is old as dirt and you shouldn't be using it in the first place.

>What is C++ compilers?
[oversimplification]
A C++ compiler is a program that takes a text file with C++ code and turns it into an executable program.
[/oversimplification]

>If I write a C++ program, will it run with all the C++ GUI/IDE editors?

Narue 5,707 Bad Cop Team Colleague

>Where can I download C++?
You don't download C++, it's a programming language. You don't download Java or Perl either, they're just languages. What you download is a compiler for C++, or an interpreter for Perl, or the development kit for Java. Too many people mistake their compiler for the language they're using, and it causes untold confusion and frustration.

>What is C++?
A general programming language based off of C.

>Who is its vendor?
It's not a software package, it's a language. There's no vendor of C++ itself.

>Is it free?
Yes, provided you have a compiler.

>From, where they maintain latest version of it available for the public download?
The latest "version" of C++ is document called ISO/IEC 14882:2003. That's the ISO standard definition of the language, and it's not freely available, nor would you want it unless you're already very comfortable with the language.

>Is it can be use quickly for a real-world example?
For a real world example? Pick any piece of software that you use. Chances are good that it was written primarily in C++.

>C++ to CGI?
C++ can be used for CGI.

Narue 5,707 Bad Cop Team Colleague

> Dude, This is just an example of traversal.
There are plenty of better examples (much better) out there already. For example. :) Thanks, by the way. If not for your post I'm not sure how long it would have been before I noticed that my coloring was messed up for string and character literals.

Narue 5,707 Bad Cop Team Colleague

>Ya but how do i get it to print hello on paper.
Start by being more specific about your compiler and OS. To do it "right" is a lot of work, but most of the time you can do it pretty easily with a compiler/system-specific solution.

Narue 5,707 Bad Cop Team Colleague

You don't set RAND_MAX, it's a constant value (usually 32767). I don't see why you would want to set it unless the range is too small for you (in which case you use a better random number generator). Tell us how you're trying to go about solving the problem, show us your code, and we'll help you with it.

Narue 5,707 Bad Cop Team Colleague

Automate your toaster to crank out some pop tarts when your alarm clock goes off. At the very least you can play with wireless transmitters, assembly, microprocessors, and probably C# too. Then write a paper on the effects of wireless munchies and how they're linked to cancer. You'll get an A+. :)

p.s. I was only mostly serious about the abbreviations. "4rm" is probably the dumbest thing I've ever seen.

Narue 5,707 Bad Cop Team Colleague

Ooh, ooh! How about a filter that cleans up those lame abbreviations that make you look like a retard? ;)

But seriously, what was the primary focus of your studies? What part of the courses did you enjoy most? You should be able to find a good project that falls under those two areas. Just be creative.

Narue 5,707 Bad Cop Team Colleague

>how about using getch() using #include<conio.h>
That's even worse. Hey, I have an idea! How about this?

#include <iostream>
#include <limits>

using namespace std;

int main()
{
  // Your code here

  // Clean up the stream and ask for input
  cin.ignore ( numeric_limits<streamsize>::max(), '\n' );
  cin.get();
}

*Whacks sunnypalsingh with a clue bat*

Narue 5,707 Bad Cop Team Colleague

>the command prompt shuts down before anything is displayed
Actually, everything is displayed just as you intended, but the window closes too fast for you to see that. This is a common problem that can be fixed simply by asking for input before the program terminates:

#include <iostream>
#include <limits>

using namespace std;

int main()
{
  // Your code here

  // Clean up the stream and ask for input
  cin.ignore ( numeric_limits<streamsize>::max(), '\n' );
  cin.get();
}

On a side note, you'll see a bunch of different ways to clean up the standard input stream, most of which are wrong in one way or another. So be wary of any suggestions except the above.

Narue 5,707 Bad Cop Team Colleague

Detail doesn't matter in this case. All you need to know is that you shouldn't assume the size of a byte in portable code because the code could be ported to an exotic system. If you stick to the most common modern machines (such as the x86 that you're probably using) a byte is 8 bits. And yet, despite the fact that most modern machines use 8 bit addressing, it's very rare when you would need to exploit that knowledge.

Narue 5,707 Bad Cop Team Colleague

>I guess byte is always equal to 8 bits
Maybe it is in your sheltered little world. But no, a byte is not always an octet (which is 8 bits).

Narue 5,707 Bad Cop Team Colleague

>Actually, it says nothing at all about the system.
That's what I said. There's no guarantee.

Narue 5,707 Bad Cop Team Colleague

>sizeof (int) gives me 4 bytes...is it sufficient to say that my machine is of type 32-bit
For your intended purposes, it probably is sufficient. But even if a machine supports 32-bit integers or has a 32-bit address space that doesn't mean it's a 32-bit machine. The term 32-bit machine is referring to the size of the data bus, and it means that 32 bits can be moved around with a single instruction, as opposed to a 16-bit machine which can only move 16 bits in a single instruction.

Also, just because sizeof(int) is 4 doesn't mean that an integer is 32 bits. The size of char is always 1 even if char is more than 8 bits, which is certainly possible. sizeof(int) * CHAR_BIT would be more accurate even though that still doesn't guarantee that your system is 32-bit. ;)

Narue 5,707 Bad Cop Team Colleague

>but this doesnt help does it?
If all you're looking for is the answer to your immediate question, it doesn't help. But if you want to become a better programmer, it helps a great deal. But some people just want the answers...

Narue 5,707 Bad Cop Team Colleague

>Replace strcpy(buffer, holdingArray[1]) with buffer=strdup(holdingArray[1]).
strdup isn't a standard function, so you shouldn't expect it to exist since there was no mention of which compiler is used. Fortunately, it's easy to write:

char *copystr ( const char *s )
{
  char *rs = new char[strlen ( s ) + 1];

  if ( rs != NULL )
    strcpy ( rs, s );

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

>Since it seems like this is just gonna go one for ever saying "it works for me" someone just lock this thread.
Maybe you should be more specific than "it doesn't work". It sounds like you're experiencing the first problem that most Dev-C++ users ask here, where the output window closes when the program terminates, and you don't see the complete output. Try this:

#include <iostream>
#include <limits>
using namespace std;

int main()
{
     cout << "Please enter 2 numbers to be added "; 
     int a;
     int b;
     cin >> a;
     cout << "\n num1: " << a << endl;
     cin >> b;
     cout << " num2: " << b << endl;
     cout << " a + b = " << a + b << endl;
     
     cout << "Press the enter key to exit";
     cin.ignore(numeric_limits<streamsize>::max(), '\n');
     cin.get();

     return 0;
}

>cin.ignore(cin.rdbuf()->in_avail() + 1);
This isn't strictly guaranteed to do what you think it's doing, for several somewhat advanced reasons that I'm not terribly interested in explaining right now. But you can treat it like cin.sync() and avoid it in favor of the above example most of the time.

Narue 5,707 Bad Cop Team Colleague

This thread has been marked solved. What was your solution?

Narue 5,707 Bad Cop Team Colleague

Write a separate C++ program that creates the file and places it where you want. Basic automation. :)

Narue 5,707 Bad Cop Team Colleague

"Script" is a very broad term that typically doesn't apply to C or C++. Can you be more specific?

Narue 5,707 Bad Cop Team Colleague

You can read them, you just can't reply to them.

Narue 5,707 Bad Cop Team Colleague

When all pertinent information has been discussed, and it appears that future posts will only cause trouble.

Narue 5,707 Bad Cop Team Colleague

>This thread started with a simple question:
And what makes you think I was referring to this thread? My experiences extend considerably further than the tiny little world of Daniweb, and I feel that it's beneficial if I bring them to bear where they apply.

>One solution was the venerable xor way.
Venerable my ass. Do you even know what that word means? If so, don't you think it's terribly inappropriate for such a despised hack?

>let's not be so bumptious about it!
But we can be "bumptious" about forcing our views that everyone should be nice to each other while actively insulting someone else? Since you're trying to use big, educated words, I have another one for you: hypocrite.

Please don't post again until you have a clue.

Narue 5,707 Bad Cop Team Colleague

>What I want to know is what is so 'clever' about these xor tricks?
New programmers invariably stumble across them and say "Hey, that's nifty! I think I'll tell everyone I can find so that I look smarter."

>Its old hat - not clever.
For us perhaps, but not for them.

Narue 5,707 Bad Cop Team Colleague

>but I didn't want to let common sense get in the way of correctly divining the way of the C(++) standards.
Wise of you.

Narue 5,707 Bad Cop Team Colleague

>Does xor have problems when a negative number is involved
Think about how the bit operations work. Does it make sense for the signed representation to affect those operations in any way?

>I do not see how xor produces overflow problems.
Once again, think about how the bit operations work. Is it possible to overflow a type by only toggling the bits in its value?

is there a hypothetical case of internal binary number representation and xor operation where a C or C++-compliant compiler would produce machine code that does not successfully swap, given certain strange values of equally-typed x and y?

Aside from the points already mentioned, no. Though there are issues where the architecture simply cannot handle an XOR swap without using temporary space, and the compiler would have to pick up the slack. Though those are implementation issues that really have no bearing here except as an argument against the XOR trick because it may not actually save space.

Narue 5,707 Bad Cop Team Colleague

>x == y works just swell
Yes, of course. We've established that my wording was poor. Try using the swap when x and y are the same variable and have a non-zero value.

>I am trusting programmers like Treedog
Who is Treedog? I haven't seen anyone by that name post in this thread, so if you're talking about an external resource, please provide a link.

Narue 5,707 Bad Cop Team Colleague

>but the code seems to work ok.
Perhaps my wording was poor. If a and b refer to the same object, the result will be 0, regardless of what the original value was. Sure, you may argue that this is an unlikely event, but I've seen it fairly often, especially in sorting algorithms.

*sigh* I tire of explaining this time and time again.

Narue 5,707 Bad Cop Team Colleague

>How is x ^= y; y ^= x; x ^= y; unsafe when x and y are equally sized integers?
Try it when x == y. Without special case tests, the XOR swap is hopelessly broken.

Narue 5,707 Bad Cop Team Colleague

>the template still produced the correct results with my compiler
That doesn't mean it worked, it only means that your compiler happens to interpret undefined behavior as the behavior that you expected.

>I don't think there is a safe way to swap two integers without using a temp variable.
Not with a template, at least, not easily. But if you write a swap function to swap two integers, you can test for overflow without too much difficulty. Of course, if you had used a temporary in the first place, all of this undefined behavior and trickiness could be avoided. Now do you see why I think it's a stupid problem?

Narue 5,707 Bad Cop Team Colleague

>It teaches creative thinking, and isn't that one of the goals of higher eduational instutions?
Bwahahahaha! No, one of the goals of higher educational institutions is to create conformists to fit nicely as cogs in the machine. If you're looking for creative encouragement, don't look at schools.

>but one that will separate the real programmers from the dabblers
Yes, yes, and the ones that don't answer: "That's silly, I'd never do it that way" are the dabblers. If I'm going to interview a programmer, and this is something I do fairly often, I'll use a more realistic question to separate the real programmers from the dabblers.

The reason for the overflow is because there was not enough memory allocated to hold the string! So yes, adding a few more bytes will fix that type of error. You can't stuff 16 characters into a 15-byte buffer, you can't push a cammel through the eye of a needle.

And don't be decieved into thinking std::string allocates only the number of bytes needed to hold the string. Of course its compiler dependent, but VC++ 6.0 version of that class allocates a minumum of 31 bytes -- even if only 1 byte is needed. Why? For speed and efficiency. It takes up too much time to allocate/reallocate exactly what is needed -- "memory of cheap" approach.

What are you babbling about? Your template function cannot swap strings, so why are you talking about strings? I get the feeling you're in the …