Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Pass it just like you would any other array

class foo
{
public:
    foo(char **ar, int n)
    {
    }



};



int main()
{
    char** mz = new char*[5];
    for(int i = 0; i < 5; i++)
        mz[i] = new char[5];
    foo f2(mz,5);
}

[edit]Oops! Sorry Narue, I didn't see your post.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I assume you mean the console screen.

First you have to figure out the screen width in characters. The old MS-DOS window was 80 characters wide, but that is no longer true. Once you know the screen width then the rest should be easy math. Something like this:

int main()
{
    std::string name = "Daniel";
    const int ScreenWidth = 80;
    while( name.length() > 0)
    {
        int center = (ScreenWidth-name.length())/2;
        cout << setw(center) << " " << name << '\n';
        name = name.substr(1);
    }
}
NicAx64 commented: MS dos is not the command shell anyway.`cmd.exe` is a command interpreter and it's completely 32-bit mode command shell ,in 64 bit environments the older protected mode environment was not exists anymore. and command.com is different from cmd.exe. +2
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

define a structure

struct coord
{
   int x;
   int y;
   int z;
};
Software guy commented: Yep so right +0
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

strcpy() does not work with single characters -- it works with entire null-terminated character arrays. If you want to copy just a single character than simply use the = assignment operator. post[j] = in[x];

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>But my compiler complaining me a warning saying strdup and strcpy both are deprecated

The only compiler that complains about that is Microsoft. AFAIK they have not been deprecated in either the C or C++ standards. So I just use a pargma to remove that warning #pragma warning(disable: 4996)

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>myValue= new char[sizeof(textVal)];
That won't work because sizeof(testVal) is nothing more than sizeof(char *), or 4 on most 32-bit compilers. What you want is myValue= new char[strlen(textVal)+1] then on the next line call strcpy() instead of memcpy().

Those two lines can be combined like this: myValue = strdup(element->GetText()); . To destroy the memory call free() instead of delete[] because strdup() is a C function that uses malloc().

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

NULL is traditionally meant to only be used with pointers, never integers or characters because originally NULL was defined as #define NULL (char *)0 So to check for the string's terminating character it would be for(size_t n = 0; myStr[n] != 0; n++) C++ now normally defines NULL as 0, so the compilers that define it that way will not have a problem with using NULL instead of 0. However, just be aware that such a program may not compile with all compilers.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

That is pointer to a function that returns char*. __cdecl is a calling convention, which is a method used by compilers to pass parameters on the stack and clean up the stack when the runction returns to its caller.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

NODE_WATER_ATTR_ENABLE is a function and Attrribute() wants a char*. Try this: element->Attribute (XMLNodeNames::NODES::NODE_WATER_ATTR_ENABLE());

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
StuXYZ commented: Nice comment, amused me. +3
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Are you too lazy to read this thread?? -- your question has already been answered.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Dev-C++ is very old and outdated, and used an old version of gcc compiler. Replace it with Code::Blocks/MinGW and you will have few problems.

NicAx64 commented: I just moved to the CodeLite right now! Bye bye Dev-Cpp. and mingw 4.4 is faster that I thaught. +2
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I have a custom user title too, because it's true that after 25+ years I'm still learning :) And I didn't like the default title -- too boastful.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

That's called redirecting stdout to a file. Output to the screen is done with either stdout or stderr (in both C and C++).

Another way to do it is for program 2 to create a pipe through which program 1's stdout is redirected through the pipe to program 2. Here is an example in C language. I don't know if it can be used with c++ fstream class or not because I've never tried it.

NicAx64 commented: Thanks for the example, learn something keep up good work. +2
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

you mean like these?

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

A little pseudocode

beginning of loop
   display "Enter your password\n";
   get user keyboard input
   if password is correct then exit this loop
   if this is the third attempt then exit this program,
end of loop
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Microsoft name mangling is a very complex topic. After a littled testing of the code in the original post to this thread I've come to the conclusion that Microsoft does include the return type as part of the mangled name. The compiler allows both versions of the function because names are mangled at compile time, not link time. Since the two classes are in two different *.cpp files the compiler has no way of knowing that the two functions differ only by return type. If you put both functions in the same *.cpp file the compiler generates the error message error C2556: 'void A::printText(void)' : overloaded function differs only by return type from 'int A::printText(void) .

To further complicate things, add a contructor to each version of the class and print out a different message in each constructor. Only one of the two contructors is called for both clA and clB objects.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The safest way for the receiver to do it would be to manually insert the streamed data into the structure. For example:

struct st_ipv4 st;
unsigned char buffer[1024]; // assume this contains the streamed data
unsigned char* ptr = buffer;
st.verion = *(uint8*)ptr;
ptr += sizeof(uint8);
st.headerlength = *(unit8*)ptr;
ptr += sizeof(uint8);
// etc. etc for each field in the structure

And an even safer way is for sender to convert everything to text and send the data as text instead of binary. That resolved the big/little endian issues too.

pdk123 commented: Understood my problem exactly and solns were really helpful..Very quick response.. +3
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

A better loop does not use eof()

while ( indata >> num ) { // keep reading until end-of-file
          
          switch(num){
                      case 'a':sara+=1;break;
                      case 'b':ri+=1;break;
                      case 'c':sat+=1;break;
                      case 'd':ha+=1;break;
                      default: cout << "oops!\n"; break;
          }
           // sets EOF flag if no value found
       }
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Ok, but shouldn't it results in compilation time error,

No because as I said before the compiler only works on one *.c or *.cpp file at a time (unless one is included in another, which is a horrible thing to do).

After all, after linking there are two methods with the same signature, but different return types...

Return types don't differentiate methods or functions. Parameters are what makes then different.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I have never "smim"ed in my life. Can you post a picture of someone smimming so that we know what it is?

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>> I don't have the time or requirements to download and install everything for Windows CE. It would be greatly appreciated.

Nonsense. You have the time to post a requrest here and wait several hours for someone to hopefully give you the *.cpp file. You could have downloaded the entire WinCE operating system by then.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Trying to do that with multiple arrays is not a good idea because its difficult to keep the data together for any given city. A more convenient way to do it is to create a structure for the data

struct city
{
   std::string name;
   int x;
   int y;
};

Now just make a vector of the above structure. It completely eliminates the need to use the new operator to allocate memory for anything.

vector<city> cities;
city c;
while( input >> c.name >> c.x >> c.y )
{
   cities.push_back(c);
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

That is how to declare a two dimensional character array. Here is a short tutorial

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You should also get 0 credit if someone else writes the program for you.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Since you are using precompiled headers, stdafx.h must be the first include file in stdafx.cpp and all other *.cpp files of the project. Other *.h files can be included after stdafx.h and will not be included in the *.pch precompiled header file.

I don't think that is the problem though because the compiler would have given a different error message. So the only other possibility is that test.h is not located in the directory you think it is. It should be in the same folder as the other project .cpp files.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Of course there are other solutions. And the one you suggested will work too. Just create another buffer and copy the contents of sCmdInt into it.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>@AD did you edit by any chance?

Yes. My statement was incorrect. C99 allows const, previous versions did not. You have to be careful about what versions of c standards people are talking about. The new Cx00 (or whatever it will be called) allows a lot of other stuff that is new to the C language. such as this

int x = 100;
int array[x];
nbaztec commented: You could've said No & make me look stupid; but you didn't :) +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

C is about as close as one can get to assembly without actually writing assembly. Before C could support nested functions there would have to be support for them in assembly language. And I know that its not supported on Intel based computers, and probably not any other processors either.

If pascal supports nested functions then the pascal compiler must be actually making them separate functions like C language because the underlying assembly language stack frames doesn't support that.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Some of those questions may be true or false depending on the version of c and c++ standards. But current c/c++ standards are like this:

>>In C program , the MAIN() should NOT RETURN a value
That's a lie, and has always been false. Either you misunderstood him, or it has no clue what he is talking about.

>>He stated I'm wrong.
Stop taking that course because all he will do is tell you more lies and mis-information.

>>C does NOT have REFERENCE variables.
True -- C has pointers

>>C++ ,REFERENCE variables are USED in functions
Obviously true. Reference variables could be declared globally but not used there.

>>C does NOT SUPPORT DEFAULT arguments.
True

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>if (Gavity.Text == 'Heavy' || 'Normal' || 'Low'){
That isn't a c++ legal statement, manage or unmanaged. if( Gavity.Text == "Heavy" || Gavity.Text == "Normal" || Gavity.Text == "Low"){ I created a simple Forms application with a combo box and a text box, then copied the selected item in the combo box into the tex box. Works perfectly, so you should be able to adapt it to your problem. The last few lines of the code below is only what you will probably need. I just posted the whole file just in case you need it.

#pragma once

namespace FormsText {

	using namespace System;
	using namespace System::ComponentModel;
	using namespace System::Collections;
	using namespace System::Windows::Forms;
	using namespace System::Data;
	using namespace System::Drawing;

	/// <summary>
	/// Summary for Form1
	/// </summary>
	public ref class Form1 : public System::Windows::Forms::Form
	{
	public:
		Form1(void)
		{
			InitializeComponent();
			//
			//TODO: Add the constructor code here
			//
		}

	protected:
		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		~Form1()
		{
			if (components)
			{
				delete components;
			}
		}
    private: System::Windows::Forms::ComboBox^  comboBox1;
    private: System::Windows::Forms::TextBox^  textBox1;
    private: System::Windows::Forms::TextBox^  textBox2;
    protected: 

	private:
		/// <summary>
		/// Required designer variable.
		/// </summary>
		System::ComponentModel::Container ^components;

#pragma region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		void InitializeComponent(void)
		{
            this->comboBox1 = (gcnew System::Windows::Forms::ComboBox());
            this->textBox1 = (gcnew System::Windows::Forms::TextBox());
            this->textBox2 = (gcnew System::Windows::Forms::TextBox());
            this->SuspendLayout();
            // 
            // comboBox1
            // 
            this->comboBox1->FormattingEnabled = true;
            this->comboBox1->Items->AddRange(gcnew cli::array< System::Object^  >(10) …
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

It is perfectly ok to use char variable as an index to an array -- in fact it is very handy thing to do at times. For example lets say you need to count the number of occurrences of each letter in a sentence. To do that just loop through the string and use each character as the index into an int array. No typecasting is needed because type char is already an integer (one byte integer).

int count[255] = {0};
std::string sentence = "Hello World";

for(int i = 0; i < sentence.length(); i++)
{
   ++count[sentence[i]];
}

for(int i = 0; i < 255; i++)
{
   if( count[i] > 0)
   {
      cout << "Letter " << (char)count[i] << ": " << count[i] << '\n';
   }
}

And now I've gone and done someone's homework.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Yes it will help. By itself it won't get you a job, but it will get you in the door to get an interview. Its up to you to show your stuff (knowledge and skills) during the interview.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

enter the time as normal and the program converts it to time_t

int hour = 10;
int minute = 30;
int duration = 4; // 4 hours
struct tm* tm;
time_t theTime;

theTime = time(0); // get current date/time
tm = localtime(&theTime); // convert to structure
tm->tm_hour = hour;   
tm->tm_minute = minute;
theTime = mktime(tm);  // convert struct to time_t

// now calculate the end time.  Just add the hours and/or minutes
// and the function mktime() will adjust all other values as
// necessary to normalize the structure.
tm->tm_hour += duration; // add the hours
theTime = mktime(tm);  // convert struct to time_t
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I would probably use containment. Don't use the name 'time' because that symbol is already used in time.h

class localtime
{

};

class date
{

};

class timedate
{
  localtime tm;
  date dt;
};
Fbody commented: Agreed, containment is much easier. :) +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

It's now been four years since the original article was posted here. c++ is still alive and thirving languge. D?? I don't know a single person who uses it.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I was in the Air Force 23 years and moved 22 times. A few times it was just from one house to another at the same military installation. If you have more than 4 years service in now it will be to your advantage to go all the way to retirement. I'm now at age 67 reaping the benefits of all those years, especially the medical benefits.

As for the degree, you will want to look closely at the coures offered for each then choose the one that best fits your goals.

As for salary, depends on where you are at. Here in the mid-west the salary for someone with a few years experience is progably $60-100K/year. If you work for Microsoft I'd expect the salary to be double or tripple that.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Either you are a very very fast programmer, or you cheated and plagiarized someone else's poorly written and non-standard code.

Fbody commented: Agreed +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

This is why we need guns for protection. I just love stories like this with happy endings :)

Glass_Joe commented: Best grandma ever +0
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Thank you for spending many years in our military -- I for one know what that is like and am able to better appreciate the sacrifices you are making.

As for that "high paying" job --- what do you consider to be high paying? And where? A bachelor's degree will certainly open a lot of doors for you, as for certs they are almost ignored. If you are considering military retirement at 20 years service you might want to consider cross training into one of the computer related fields. That will give you the experience you might need to make yourself even more competitive in the civilian work force.

As for whether you should be a BS in Management Information Systems (MIS) or Computer Science (CS) it depends on how much mathahetics you like. CS is more math and hardware technical oriented than MIS. MIS is more for solving business problems using programming and databases, not as theoritical as CS.

IT cllge stdnt commented: Thanks for posting and the advice!! +0
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You need to force Form to repaint itself before each Sleep(). I'm not sure how to do that (I don't normall write CLR code) but here is a start.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Yes, I actually had the statement backwords -- should have been == 0 as previously noted.

The not operator ! means 0, not false. There is no requirement for false to be 0.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

There is no such thing as = !!. What you want is != 0

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Stack::Node says Node is a structure defined inside class Stack.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Betty Boop

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

No one said programming is easy. It might be easy for some people, but for us mear mortals learning it can be difficult and very very time consuming.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

:)What you used to do all night now takes all night to do

More like: what you used to do all night is now impossible to do at all.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The first thing you need to do is understand the mathametics. Use pencil & paper and work that out so that you know how to make the calculations.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

what does

if( strcmp(output, "file.txt") == 0)

do?

I don't intend to sound mean, but look up strcmp() in your textbook or google for it. If you can't undedrstand that then you are attempting to code stuff that is over your head. You need to start over and read your text book again from page 1, do all exercises, or read online tutorials more thoroughly.


>>Just use strings.
That doesn't help learning character arrays.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>cin is a buffer, it needs to flush, just like cout
No it is not a buffer -- it is a c++ class. And cin can not be flushed. flush() only works on output streams, never input streams.