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

It appear you are declaring the same object in two *.cpp files. That will happen if you declare something in a header file then include that header file in all *.cpp files. What you need to do to corect that is declare it with the extern keyword in the header file, then on only ONE of the *.cpp files declare it again without extern

// header file named myheder.h (or whatever name you want to give it)
extern double u_err;
#include <myheader.h>
// one of the *.cpp files
double u_err = 0.0;
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The problem is that m_buffer is being deleted too early. Here is the correction. I had not anticipated that you would make the parameter to the append function a reference to itself.

String& String::append(const String& other)
{
 int newlen = strlen(other.m_buffer)+ m_length + 1;
 char *temp = new char[newlen];
 temp[0] = 0;
 if( m_length> 0)
 {
     strcpy(temp,m_buffer);
//     delete[] m_buffer;
//     m_length = 0;
 }
 else
       temp[0] = 0;
 if( other.m_length > 0)
      strcat(temp,other.m_buffer);
 delete[] m_buffer;
 m_buffer = temp;
 m_length = newlen;
 return *this;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Oh, I see you are using c++ managed code. You will have to convert char* to System::String -- I don't know how to do that because I've never written managed code. Someone else will have to help you, or you can look it up in your text book, or google for it.

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

Re-read my previous post.

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

>>temp.m_buffer=new char[] m_length;

Shouldn't that be this: temp.m_buffer=new char[m_length]; >>if(!m_length)
That means if m_length == 0. When that happens strlen(other) == 0 and the previous new operator will return a pointer to a 0-length character array. So if the length of the allocated buffer is 0, how in the world can you expect the strcpy() to succeed?

posible suggested change: (Not compiled or tested, you will have to do that).

String& String::append(char *other)
{
  
 int newlen = strlen(other)+ m_length + 1;
 char *temp = new char[newlen];
 temp[0] = 0;
 if( m_length > 0)
 {
    // move existing buffer to temp, then delete m_buffer
     strcpy(temp, m_buffer);
     delete[] m_buffer;
     m_length = 0;
 }
 else
       temp[0] = 0;
  strcat(temp, other);
  m_buffer = temp;
  m_length = newlen;
  return *this;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

1) open the file

FILE* fp = fopen("myfile.txt");

2) use fprintf()

fprintf(fp,"%x", 123);

How difficult was that??

But this is c++, so you should be using the functions in <fstream>

#include <fstream>
using namespace std;

int main()
{
     ofstream out("myfile.txt");
     out << hex << 123 << "\n";
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

why do you need Convert::ToStrig()? coln is already a string, just send it to testBox1->Text.

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

First you have to populate the two arrays dogs and cats. cin might be useful for that. After that is done then use a loop to sum them up

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

Now i have done with the entire writing of the 1st row, to be frank, i am not really sure how to load it back.

edit: since i know which line and column the data is in within the .csv file, any idea on how to directly get to say line 6, column 8 with all those commas in the line?

Thanks in advance.

You can't go directly to row/column in a text file. The only way to do it is to sequentially read each row until you get to the one you want. One way to do this might be something like this:

#include <string>
#include <fstream>
#include <sstream>
...
...
std::string line;
ifstream in("file.csv");
int lineToGet = 6;
// read all lines until you get to
// the one you want
for(int i = 0; i < lineToGet; i++)
    getline(in,line);
// now that we have the line we want,
// split it into columns
stringstream str(line);
std::string column;
for(int i = 0; i < 5; i++)
   getline(str, column, ',');
// now, the 5th column is in variable [b]column[/b]. 
// Since its enclosed in double quotes you will
// have to strip those out before adding to your Form
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>How about loading it back to window form, any pointers on this?
Not really, without knowing how you are doing it now.

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

allocate and top the string first then reset pointer a

char* temp  = new char[n];
    char* p = temp;
    memset(temp,' ',n);
    temp[n-1] = 0; //null  terminate
    memcpy(temp, a, strlen(a));
    a = temp;
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

To change the value you have to completely rewrite the entire file. You will have to write the file back out in the same format from the data that is in the Form.

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

Learn to use your compiler's debugger and single-step through your program to see what is happening. The problem could be in whitelist() function or somewhere before that function is called. Its impossible for anyone to analyze your program without seeing the code.

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

If the classes can be plugged into other projercts without change then make a shared library out of them. That way there is only one set of source files and the projects all link with the same library.

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

>>everytime pin or checks is not a null string it throws a GPF.

>>checks and pin are strings

Do you mean std::string declared in <string> header file? Those are not null-terminated strings at all but c++ class.

Post the function prototype for whitelist(checks, pin, wkbool, wqbool, enpassant)

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

That's true -- it doesn't take one parameter. You need to look up the functions you want to use either in your compiler's printed docs (if they still have them) or on the net (ever hear of google?). Don't just toss functions on a *.cpp file and expect the program to compiler.

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

That is what i wanted to do, i want to use the same variables , but i don't know how to do it exactly

I just told you how. Add the two variables as parameters to the function then pass them on line 37, just like you would pass a variable to any other standard function. And don't forget to change the function declaration in the class iteself. Findlly, delete b and k on line 23.

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

you are looking at the wrong line -- see line 26 in the code you posted above, which may or may not be the same line in your compiler.

The variables b and k declared on line 31 are not the same as the variables declared on line 23. If you want to use the variables declared in main() then you will have to pass them as parameters to Bata() function. double Gama::Beta(int b, int k) Another option is to make b and k members of the class.

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

use fgets() -- never ever gets() -- to read the entire line from a file or from the keyboard.

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

The variable k is being used without being intialized
what does this meen?

Look at like 26: what is the value of variables b and k? Answer: their value is just some random number that happens to be in the memory location when the function started. You need to set b and k to some number before that loop starts.

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

what is wrong with it?

line 37: geta() is a function -- you need to add the ()

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

The implementation of cin and cout is compiler/os dependent. On MS-Windows I suspect Microsoft implemented it by using win32 api console functions. And, as others have said, this is very advanced programming. Here is some source code if you are up to the task.

You will find more information here.

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

That's the spirit.
Here's some more food to it.

Yes, I agree that Obama is the Second Coming of Christ that was predicted in the Bible some 2,000 years ago. We will now start 1,000 years of peace on earth.

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

>> I would be somewhat surprised if binary is "a lot" faster than text.

What I meant by that is the fwrite() function (binary writing) is a lot faster than fprintf() (text mode writing).

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

The functions in either stdio.h or <fstream> will do the job equally well, but for c++ most programmers would recommend <fstream> for consistency. If all the characters you want to write are all in one large block of RAM than you would write the file in binary mode, which is a lot faster than text mode.

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

>>all that remains is to figure more about "cls","dir"
We already told you how to do those.

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

>>Ive been taught C this way.
You were taught wrong for most compilers.

The newest version of the C standards will allow you to declare objects anywhere you want, just like the C++ standards has done all along. The problem is you need to find a compiler that is new enough to implement that standard. VC++2008 also will not compile that code.

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

You have to be careful about string literals such as what you just posted above ^^^. String literals are (normally) stored in read-only memory so they can't be changed. What you posted originally is correect because the array isn't a string literal but a character array: char p[] = " smith";char*a = p; You can pass that to your trimLeft() function but not this: char *p = " smith";

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

If you want to set all elements to 0 then you can use memset(). Microsoft compilers implement that function in assembly because the chip has an instruction that will do it, and that is about as efficient as you can get. I don't know how other compilers implement it.

Also use the = {0} when declaring the array. int myarray[255] = {0};

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

>> But what i fail to understand is that when i'm passing the address of array and incrementing the pointer why is it not having as the same effect as the code that you have given

Because you did not pass the address of the pointer -- all you did was pass the address of the start of the character array, which is not the same thing. Look closely at the & symbol in the trimLeft() function declaration -- that is a reference to a pointer.

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

You can use Code::Blocks compiler, which is more up-to-date than Dev-C++.

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

I think what Freaky means is there is no one set of c or c++ functions that will do everything you want for all platforms.

To make a program cross platform you have to write all the code for all platforms then use conditional precompile directives. For example, if you want windows and unix

#ifdef _WIN32
// code here for windows platform
#elifdef _UNIX
// code here for unix platform
#elifdef _SOMEOTHER PLATFORM
// code here for the other platform
#endif

Of course that make the source code quite large, if you want just one source file to do everything that is the only way it can be done. Then you have to compile the program on each platform you want to support and define the appropriate symbol in the compiler you use.

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

A buffer is normally just a block of memory where things can be stored in RAM. A stream is something that lets you store things on disk, send across to other computers such as the internet, serial port, UCB, etc. streams often use buffers to optimize transmission speed. For example instead of writing data directly to disk the stream (e.g. ofstream object) might store it in a buffer and write to disk when either the buffer is full or when there is available time such as while the program is waiting for keyboard input.

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

Question: Who is not looking for good job in these times of depression?

Not me :)

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

go there and look around -- you have a computer too.

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

I'm still not at-ease in giving credit card information through the net, and any personal information whatsoever.

I'm with you -- I don't buy anything on the net unless that's the only way to get it. There are just too many instances of where huge company databases have been stolen by credit card thieves. If the datase is available on the net then its not safe.

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

Hi Need a cheap UK host please! Any help?

Check here in their Freebies forum. That site might have what you are looking for.

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

trimleft() does nothing. After finding the last space you need to shift all remaining characters left. memmove() will do that for you, or you can do it yourself using two pointers.

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

list errors.

The last line -- VC++ 6.0 is old style C which forces you to declare all objects at the beginning of function.

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

try googling because it will answer many of the questions you have. The solutions are not simple, so you will need basic understanding of C and/or C++ languages.

windows console functions

clear windows console screen

This one I wrote to show how to use FindFirst() and FindNext() win32 api functions. Its not exactly what you want but should give you a start to write your own dir command.

list directories

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

I don't see why not. Go to www.gnu.org and see if you can find the code there.

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

Windows tutorial here. But you need to know C or C++ first.

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

1) delete line 87 because its unnecessary. The function is prototyped in the header file.

2) line 108: time_after is never declared (see spelling on line 89)

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

You posted crappy unrealistic options.

You can't learn Windows development without knowledge of either C or C++ (or some other computer language as well). So options B, D and E are impossible assuming you don't want to know about other languages. That leaves only options A and C as viable options. F I suppose is to do nothing.

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

Welcome to DaniWeb. For link exchange, look here

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

This has been reported before, but I can't find the thread at the moment. As I recall (maybe wrongly) that comment is intentional.

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

And how do you think DaniWeb should read your mind?