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

Your version doesn't work because the first parameter Dest needs to be passed by pointer, not by value

#include <iostream>
#include <cstring>
using std::cin;
using std::cout;

void StrCpy(char ** Dest , char* Src )
{
 int i;
 char *tmp = new char[strlen(Src)+1];
 for(i = 0 ; *Src!='\0' ; Src++)
    tmp[i]=*Src;
 tmp[i]='\0'; 
 *Dest = tmp; 
 for(int i= 0 ; tmp[i]!='\0' ; i++)
   cout << tmp[i];
}

void main()
{  

char *string1 = 0;
char * string2 = "EL";


StrCpy( &string1, string2);
 // while(*string1)
 //   cout << *string1++; 
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

My guess is that in main.cpp, the Graph object has not been initiaized, so when ReadGraph() is called and attempts to delete arrayEdges, CRASH/COREDUMP.

In main() initialize all Graph variables to 0 before calling ReadGraph() to see if that resolves your problem.

int main()
{
    Graph g;
    memset(&g, 0, sizeof(Graph));
    readGraph(g);
<snip>
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

What about Buffer Overflow? :P

That is a problem with all standard C functions. If you use one of the new Microsoft compilers, Microsoft declared them depreciated and wants us to use the _s functions, such as strcpy_s(), which has an additional destination buffer size parameter. But even that could cause buffer overflow if the calling function passed the wrong buffer size. There is no 100% bullet-proof method in C to prevent buffer overflow. But if you follow the rules and bother to actually read the function's requirements then you can minimize the buffer overflow problem.

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

can I just add, you need to remember to add a *dest=0; line after the while. You will need something similar in any of the other posts.

No with Arkm's algorithm you don't because it will also copy the null terminator.

StuXYZ commented: Your correct, I don't know why I hadn't noticed that! +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>I did was to Initialize char * string1 = "longer than string2" and evrything else the same and it didnt work either
I didn't work because you can't change string literals, which is what you attempted to do. But you could have done it like this: char string1[] = "longer than string2" , which will put the text in writeable memory.

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

You are attempting to stuff 3 bytes (string2) into a character array that is only 1 byte (string1). Try this:

int main()
{  

char string1[4] = {0}
char * string2 = "EL";

StrCpy(string1, string2);
//cout << string1; //must output EL
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Is MSXML installed on your computer? You have to download and install it from here.

And make sure you read all of this article

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

If the hardware is too old then Vista won't even install. Needs to run the Vista Upgrade Advisor before spending money on a new hd to see if he needs a whole new computer.

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

If you are going to buy a new hard drive get the biggest one you can affort because in a couple years it won't be big enough!
A few years ago the first hd I bought was 80 meg and cost about $500.00 USD. I thought it would last forever, but forever turned out to be about 6 months when I filled it up with MS-DOS 6.X os. I have bought several since then and MS-Windows seems to be getting bigger and bigger as hardware gets cheaper.

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

There are a couple approaches in c++ language:

1) if input is in the form of a std::string object, you can use it's find() method to determine if it contains any of the words, example:

std::string input;
cout << "Enter a word\n";
cin >> input;
if( input.find("ONE") != std::npos)
{
    // found it.
}

2) The other way, using standard C style character arrays

char input[20];
cout << "Enter word\n";
cin >> input;
if( strstr(input,"ONE")  != NULL)
{
   // found it
}

Now if course you will have to change the above to check each of the words listed in your assignment, as well as all the other requirements which I did not mention.

And don't forget to include the appropriage header files.

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

that doesn't work if your program does not have a message pump. I've never tried it in a dll but I do know it doesn't work in a standard C/C++ language console program.

You might want to write a small C windows program that tests your dll to see if you can get the dll to work like you want it.

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

I don't see a problem with that code. It is legal and ok for a class to return a string like that.

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

First, the arrays have to be pointers so that they can be allocated at runtime. For example: float *x[2]; float * fx[2], Next, after finding the upper_limit (line 26) you can use malloc to allocate the arrays of the proper size

int i;
for(i = 0; i < 2; i++)
{
    x[i] = malloc(upper_limit * sizeof(float));
    fx[i] = malloc(upper_limit * sizeof(float));
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Depends on what you are attempting to do. If you want to see the file contents only after it has been changed by the other program then your only choice is to close the file in your program and reopen it.

If, on the otherhand, you want to see the original contents of the file you have a couple options:

1) After opening the file read the whole thing into memory and work with that.

2) Use some os-specific function to lock the file when it is opened so that other programs can not change it. ON MS-Windows you can use the win32 api fucntion _fsopen()

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

You mean while reading the file there is another program changing it? If that is correct, then all bets are off because the results of your program will be unpredictable. Your program gets the original file probably due to disk cashing -- when the file is opened the program just reads the entire file all at one time then doles it out to your program a little at a time.

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

loop is incorrect. Here is how to read until end of file. fgets() returns NULL on end-of-file or some other type of error.

while( fgets(s, MAX_BUFF, file) != NULL)
{


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

you would leave B and poly as they are, just add another long long variable for sorting purposes. When two structs have the same B value the long long will auto sort by poly. This is similar to the approach databases use when more than one field are needed to create a unique key.

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

There are several ways to solve the problem. One way is to create a 64-bit int in the structure that represents both B and poly at the same time, which will result in unique values for each structure in the array. Your program could set that value just before inserting the structure into the array

struct EDGE
{
    int  poly;
    double inv_slope;
    int B;
    long long sortValue; 
            
POINT3D p1, p2;
};

...
sortValue = (long long)B << 32 | (long long)poly;

Now you can code radix sort by sorting the sortValue member variable.

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

That is C code, not C++. Are you sure you are in a c++ class?

for a fstream tutorial click here.

cout is quite easy to learn. First you have to include <iostream> header file -- it does not have a .h extension. Then declare the std namespace.

#include <iostream>
using std::cout;

int main()
{
    cout << "Hello World\n";
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

try this

//function to clear all pointers
void clearMemory(bus* &pointer)
{
  bus *next;
  bandMember *current;
  
    
  next = pointer;
  while(next != NULL)
  {
      current = next->memListPtr;
      while(current)
      {
        bandMember *hold = current;
        current = current->memberPtr;
        delete hold;
      }
    bus* hold = next;
    next = next->busPtr;
    delete hold;

  } 
  pointer = NULL;
}

void Add(bus*& head)
{
    bus* node = new bus;
    node->busPtr = 0;
    node->memListPtr = 0;
    if(head == NULL)
        head = node;
    else
    {
        bus* next = head;
        while(next->busPtr)
            next = next->busPtr;
        next->busPtr = node;
    }
}

int main()
{
    bus* head = 0;
    for(int i = 0; i < 5; i++)
        Add(head);
    clearMemory(head);
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Could be no one here knows what you are talking about. What is "lame binding for phython" ? Of course I know what phthon is. Are you trying to call phython from C/C++ (or reverse) ?

>>Where can I get that simple yet safe DLL to play with CTYPES

You can write it yourself.:ooh:

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

'ç' has a decimal value of -25, and isdigit() only works with positive signed integer values.

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

There are hundreds of reasons you get that problem, so its impossible for us to give you much more info without seeing the code. Try commenting out large portions of the program until the crash no longer happens, that way you can narrow down your search for the problem. Look for buffer overruns and uninitialized variables, especially pointers.

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

when using character arrays the == operator does not compare string content but string addresses, so it will never work. You need to call strcmp() which returns 0 if the two strings are exactly the same. if( strcmp(name[i], "Jack Danial" == 0) . strcmp() is case sensitive, meaning "Jack" is not the same as "JACK". Many compilers have case-insensive compares, such as stricmp() or comparenocase().

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

No, it is a win32 api function so it will work with both console and MS-Windows GUI apps. If you are writing a game using some type of game engine such as OpenGL or DirectX then use whatever that game engine provides.

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

How about the win32 api function PlaySound()

I have not attempted to generate a wave file, but if I did I would probably start here

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

you don't need a loop. Just multiplication and the mod operator will do it

int main()
{
    double n = 123.45;
    int x = (int)(n * 100);
    x = x % 100;
    cout << x << "\n";
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

line 14 is wrong -- in the format string replace the comma with a space like this: scanf("%d %d", &base, &exponent);

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

Where was defined the type ptr?

See line 32.

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

I assume you are talking about MS-Windows operating systems. If not, then ignore this.

maybe the example in this link and this will help you. It shows you how to mount a network drive. If WNetAddConnection2() fails and returns ERROR_ALREADY_ASSIGNED then the drive is already mounted. Also make sure to read the remarks at the bottom of the page.

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

Node is defined within class AVLTree and only has scope within that class, so in order to use it as a parameter you need to declare its scope. Try this: void AVLTree<T>::levelorder(AVLTree::ptr& root)

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

put the code in a library or DLL than only distribute the lib or DLL along with the header file(s) that declares the function prototypes to the users. That is the common way to do it. Example: all the win32 api functions are in DLLs or libraries.

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

depends. If the file system is going to be all new then you will have to write a cross compiler first that will target the file system.

If you plan to use one of the existing file systems such as that used in *nix or MS-Windows then you can use one of the existing compilers.

I have not written an os, but I would imagine parts of it may need to be in assembly because there are some assembly instructions that have no c counterpart.

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

COM only works with ActiveX components or Windows Services programs, all of which must be registered before they can be used. Here is how to register them. If that registration fails then its not written as a COM component and therefore can not be used the way your attempting to use it.

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

Whose class is Cryptographer ? Is it registered ?

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

Since there are hyphens in the string that function won't work because it will return false on detecting the first hyphen. You need to check that the string consists of 3 digits, hyphen, 2 digits, hyphen, and 4 digits, and that all the digits are not zero.

Or you could buy for $24.99 this library. :) But I doubt that your instructor wants you to go that far in validating SSN.

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

I'm not saying you can't do it in c++, but it will bring a lot of baggage (such as stl classes) that you may not want or need. C will be tighter code, smaller code, and often faster code.

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

C is probably a better language than C++. Lots of operating systems have been written using C.

>>The next question I have is where to start.
Here are some google links you should read

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

If your program is being compiled for UNICODE and the string is non-English, then more than likely it can not be converted. If English, then there are conversion functions.

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

you don't initialize variables in header files becuse the variables don't exist. You have to declare variables in *.c or *.cpp files. You can, however, use the extern keyword with variable in header files, but again they can not be initialized there.

// myheader.h file
extern int myint;

Then in one, and only one, *.cpp file you declare the same variable but without extern keyword. You can also initialize it then.

// myprogram.cpp
#include "myheader.h"

int myint = 0;
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

That's because you enclosed the \0 in double quotes. Change it to single quotes pPtr->myArray[127]= '\0'; If myArray is less than 128 bytes then the above will cause buffer overflow.

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

After cin >> choice; you need to flush the keyboard buffer of the '\n' character (Enter key). Just add cin.ignore(); after those lines and it should work

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

Briefly, here's one way to solve it from Narue's post

#include <ios>
#include <istream>
#include <limits>

void ignore_line ( std::istream& in )
{
  in.ignore ( std::numeric_limits<std::streamsize>::max(), '\n' );
}

With that, all you have to do is call the function ignore_line(cin);

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

Well, what is wrong with the code you posted? Compiler errors/warnings? If yes, what are they?

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

>>getline(cin, partDescrip);
That should work ok assuming partDescrip is std::string. Why the program skips it is due to other parts of your program. If you have input for integers then you need to clean out the input keyboard buffer of the '\n' that is left. Right after the input integer add cin.ignore('\n'); , or for a more detailed explaination see Narue's thread here.

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

your program does not allocate any memory for the line. And your program does way too much work! This is all that is needed.

std::string line;
int i = 0;
while( i < 7 && getline(inputfile, line) )
{
    i++;
}
cout << line << "\n";
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

First you will have to change the DLL to accept the parameters that you want. That means you will have to recompile the dll with the new set of parameters.

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

. But this is a problem that is incredibly rare on modern machines - and running out of memory (not being able to allocate any) would ultimately lead to system issues much bigger than your program executing :P

You are right about that -- the entire computer would just crash and die if that ever happened. For that reason I don't check for allocation failure any more. It was necessary 15 years ago under MS-DOS 6.X and earlier, but not today. Program runs the computer out of memory -- just toss more memory at it :) But that would normally indicate a huge memory leak that needs to be fixed.

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

lines 214-218: This will not work because the new operator does not return 0 when memory allocation fails -- it throws an exception. If you want to check for that then you need to use try/catch blocks.

The code you posted is a good example of the MISUSE of unions. If you (or your instructor) had used base class and inherentence then you would not need that DataType structure at all nor would you need all those overloaded methods such as lines 76-79.

As for your actual problem, don't know the answer because we don't have all the code to compile and test.

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

how did that even compile? It is missing two closeing } character. Assuming that is just a posting error the code looks ok to me.