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

Your program worked ok for me using vc++ 2010 express on Windows 7. But I don't understand why it contains a while(1) loop? One possible reason that it crashes on you is because the code never calls GlobalUnlock().

>>when I copy a file the program crashes

Copy a from to where? I don't understand that statement.

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

You are of course right if all you want to find out if there were any non-digit characters entered and not interested in what the characters actually were.

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

you can expand ./folder into /home/user/folder by calling cwd(), assuming ./folder is the current working directory. Then you can compare the two absolute paths to see if one is in the other or that they are the same.

You could produce the string ./folder from /home/user/folder, but it won't work if the current working directory is not /home/user. For example if the program changes directory to /etc then ./folder becomes meaningless.

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

The easiest way to validate addBalance is to get user input as a string instead of int. Then you can check each character of the string for valid digits.

isalpha() doesn't work for you because the parameter to isalpha() is a single character, not an integer.

Example:

std::string input;
cout << " You can now add some fund to your account. How much do you want to add?\n" ;
while(1)
{
   getline(cin, input);
   // check input for non-digits
   bool valid = true;
   for(size_t i = 0; i < input.size() && valid == true; i++)
   {
      if( !isdigit(input[i]))
      {
        cout << "Error\n";
        valid = false;
      }
   }
   if( valid )
      break; // exit infinite loop
}
int addBalance;
// convert from string to int
stringstream str(input);
str >> addBalance;

[edit] Didn't see Narue's solution when I posted this ^^^

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

If you wrote the program then why don't you know about the username and password?

frogboy77 commented: valid question +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>How can I check if a user inputs a number other then numerical number display error and take him/her back to same question again?

Get input as a character array insted of int then you can check for non-digit entries. If its ok then convert it to an int.

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

Even at 63 I'm still having fun and will continue for some years. Been at it for over 35 years. Have fun!!

That's exactly the reason I'm so active here :)

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

what is exe ? Is that an array of char?

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

what is that link you posted? That code worked perfectly for me using vc++ 2010 Express. Here is the complete header file, the function I posted is at the bottom

The program allows me to enter digits, '-' and backspace.  All others are ignored.
#pragma once

namespace test2 {

	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::TextBox^  textBox1;
    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->textBox1 = (gcnew System::Windows::Forms::TextBox());
            this->SuspendLayout();
            // 
            // textBox1
            // 
            this->textBox1->Location = System::Drawing::Point(52, 65);
            this->textBox1->Name = L"textBox1";
            this->textBox1->Size = System::Drawing::Size(201, 22);
            this->textBox1->TabIndex = 0;
            this->textBox1->KeyPress += gcnew System::Windows::Forms::KeyPressEventHandler(this, &Form1::textBox1_KeyPress);
            // 
            // Form1
            // 
            this->AutoScaleDimensions = System::Drawing::SizeF(8, 16);
            this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
            this->ClientSize = System::Drawing::Size(282, 255);
            this->Controls->Add(this->textBox1);
            this->Name = L"Form1";
            this->Text = L"Form1";
            this->ResumeLayout(false);
            this->PerformLayout();

        }
#pragma endregion
    private: System::Void textBox1_KeyPress(System::Object^  sender, System::Windows::Forms::KeyPressEventArgs^  e) {
        if(Char::IsDigit(e->KeyChar) )
            return;
        if(e->KeyChar=='\b')
            return;
        if(e->KeyChar=='-')
        {
            if( this->textBox1->Text->Length == 0)
                return;
        }
        e->Handled=true;
             }
    };
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Oh yes -- I had the wrong event handler.

>>but i started C++ yesterday
This is not c++ -- its CLR/C++, more specifically Windows Forms.

Here is one way to do it

private: System::Void textBox1_KeyPress(System::Object^  sender, System::Windows::Forms::KeyPressEventArgs^  e) {
        if(Char::IsDigit(e->KeyChar) )
            return;
        if(e->KeyChar=='\b')
            return;
        if(e->KeyChar=='-')
        {
            if( this->textBox1->Text->Length == 0)
                return;
        }
        e->Handled=true;
             }
    };
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Only the operating system can determine where a program is loaded because there are probably other programs in memory whose address may conflict the the one you specify. The program loader reads the program into memory, finds out where to store it, then resolves all program addresses to actual physical address, such as resolves the addresses of all call statements. Even MS-DOS 6.X and earlier work that way because of TSRs (Terminate and Stay Resident, which are the grandfather of modern device drivers).

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

Add a flag (bool) to the class that indicates whether the '-' character has been seen in the text or not. Shouldn't be all that difficult for you to figure out.


KeyChar is not a member of KeyEventArgs. Do you mean KeyCode?

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

you will have to keep track of where the '-' occurs -- it can only occur at the beginning of the text, no where else.

AFAIK the '\b' will never ever be in the text box. Windows Forms text control will hangle back spaces for you. So you should never have to be concerned about it.

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

0x08 is a backspace
0x6d is the letter 'm'

Don't you want something like
if( Char::IsDigit(e->KeyChar) || e->KeyChar == 0x08 || e->KeyChar == '-')

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

You need to learn SQL and become intimately familiar with all the major databases, such as Microft SQL, MySQL, Oracle, and Sybase. You will have to know how to create datases, design them, how to use schemas, how to manage databases. Here is a wiki article that gives much more detailed information.

You might even want to go back to college and get another bachelors degree in CS.

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

One possibility is that employee.bin file does not exist or is empty.

You open the file in text mode but read it as if it were open in binary mode. On line 7 open the file in binary mode input_file=fopen("emp.bin","rb"); You didn't post struct employee so we have no idea what it contains.

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

What kind of tools do you mean? compilers, editors, project management, source code archivers

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

Where to begin what? If you want to know how to bake an apple pie then you are in the wrong place.

Nick Evan commented: :) +0
jonsca commented: I'm looking for a good recipe if you have one +0
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

If you use VC++ 2010

void foo()
{
   int x = 0;
   _asm
   {
      mov [x],1
   }
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Maybe he meant typecasting ?

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

Never heard of it. In what context did you read it?

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

Would you care to explain a little more what the problem is? You posted several while loops -- which one(s) is giving you the problem?

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

Your suggestion is no different than Narue's. CreateFile() with CREATE_NEW will fail if the file already exists. Same, but opposite, behavior that Narue suggested.

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

How are you trying to display them? Are you compiling your program(s) with UNICDE enabled ?

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

You'll most likely have to ask the game support team.

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

Not from me because I've never written an archive program and don't intend to do so now either. Shouldn't be too hard though, just use a structure for the header and save the structure at the beginning of each file.

struct header
{
  char filename[255]; // max possible file name
  unsigned long filesize; // size of the file
};
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The archive file will have to contain some sort of header record for each of the files it contains so that the files can be reconstructed after being archived. The header record would probably contain the file name and file size. Most archive programs compress the files too so that the archive file is a lot smaller.

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

use icode tags instead of quote tags to preserve the spacing.

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

You can use any character you want to flag the record as being deleted -- just use a character that is not likely to be valid in the record. Using '\0' may not be your best choice because that will make the file binary. I'd use something like tilda, or '~'. To do that all you have to do is fseek() to be beginning of the file and fwrite() a single charcter. Note that this will not prevent your program from reading the entire record. Your program has to learn that the '~' character means the record is deleted and should therefore just ignore it.

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

I already told you your code is wrong and how to fix it. You have not posted your corrected code. And you can easily check it yourself by compiling and running it. When you run that program it will tell you whether it is right or wrong.

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

Express version does not support that. You have to buy either te standard or better version.

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

Yes, I know what you question was -- but you asked if it was done. How am I supposed to know if you are finished with it or not?

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

"setup and deployment"??? AFAIK the Express version does not have such an option.

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

I don't know if you are done or not -- that's up to you to determine.

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

Reading the input stream is the only standard way to do it. That means you have to dynamically expand the input buffer with realloc() while reading the input stream.

vedro-compota commented: +++++++++ +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Go to bed, get some sleep, then work on it tomarrow when you have a fresh mind. Afterall, if you can't be bothered to study that link that I can't be bothered to tell you how to do it.

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

srand() is ued to seed the random number generator. If you call srand() with the same number every time your program is run rand() will generate the same sequence of random numbers, which is the default if the program never calls srand(). To get rand() to generate a different set of random numbers each time the program is run you need to call srand() with a different seed number. The easiest way to do that is to call time() function from time.h, like this: srand( time(0) ); you might have to typecast the return value of time() to unsigned int if your compiler complains about it.

What srand() does not do: that function does NOT set the lower value of the numbers returned by rand(), as you are implying in your program. See the examples here to find out the correct way to do that.

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

Do not use system() to start the app that was extracted from the cab file. Under MS-Windows you will have to learn how to call the much more complicated win32 api function CreateProcess()

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

Good work :) :) Your persistence has paid off :)

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

It can also be rewritten as

int c;
while( (c = fgetc(stream)) != EOF)
{
   // do something here
}

Notice there is only one call to fgetc(), not two. Also not that fgetc() returns an int, not char because EOF may or may not fit in a char variable.

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

Since this is school work, and the thread is over 3 years old, its not likely that the op will post the final program. You will just have to write it yourself.

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

To attach a doc ---

Look just below the Quick Message editor and you will see two buttons -- "Post Reply to this Thread" and "Use Advanced Editor". Click the "Use Advanced Editor".

Next, scroll down until you see a button "Manage Attachments" then click that button. That will let you browse your computer's hard drive for the file you want to upload to DaniWeb and attach to your post.

Suggestion: Don't attach anything with *.doc extension -- most people will not read it because so many *.doc files contain viruses. Instead, convert it to *.txt file and attach that to your post.

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

I don't go to hardware forum very often -- I'm not a hardware person. My experience is in C and C++ programming. There are other members here who are much more capable of answering hardware questions than I am.

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

The ThreadProc parameter to CreateThread() must be either a simple global c-style function or a static method of a c++ class. You can not pass non-static class methods to any win32 api function.

line 12: handl = &thr_handl;

Just what do you expect to accomplish with that statement??? As soon as the function ends the pointer will be invalidated because thr_handl will get auto destroyed.

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

You can post, answer questions, or just browse around. It's up to you and no one will critisize you for whatever you want to do.

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

you learn to read the previous comments

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

Your program doesn't work because it is destroying the ch1 pointer on each loop iteration. You can't increment ch1, just leave it along after the initial allocation with malloc(). Use a different pointer or integer.

Another problem is that your program is very very slooooow -- malloc() and realloc() are rather time consuming, so instead of allocating just one character at at time you should allocate a block of characters, then when the block is filled up you should call realloc() to increase the block

#define BLOCK_SIZE 80
int block_size = 0;
int current_spot = 0;
char* c1 = 0;
char c;

while( (c = getchar()) != EOF )
{
   if( block_size == current_spot)
   {
       c1 = realloc(c1, block_size + BLOCK_SIZE); 
       block_size += BLOCK_SIZE;
   }
   c1[current_spot] = c;
   ++current_spot;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Post your code or do you think we are mind readers?

malloc() and calloc() work perfectly -- its your code that doesn't work for some unknown reason.

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

just use WinZip -- it already does that.

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

make that check at line 40 of the code snippet you posted. If you don't want to process any subdirectories at all then delete lines 37-43, just leaving an empty if statement.