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

line 32 and 33: That doesn't work because the string is located in read-only memory, and attempting to write to that memory will most likely fail. Correction: This puts the string in writeable memory. char BlankPattern[]="###############"; line 39: The above doesn't work either because you can not return a character array from a function. So your only choice is to allocate memory. Note that the calling function will have to call delete[] to properly destroy this string.

char* BlankPattern = new char[16];
    // copy at most 15 characters to BlankPattern
    // if [b]string[/b] is longer than that, then the remaining
    // characters are ignored.
    strncpy(BlankPattern, string, 15);
    // now fill remaining positions with '#'
    for(int n = strlen(string); i < 15; n++)
        BlankPattern[n] = '#';
    BlankPattern[15] = 0;
    return BlankPattern;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>are you think that is true
Maybe, and maybe not. Post the class. Does it contain std::string or char* ? If yes, than that won't work because the actual text is not part of the class, only a pointer or c++ class object (std::string).

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

Yes, StuXYZ is correct about using pointers

int main (int argc, char** argv)
{
    std::vector<std::ofstream*> fileList;
    fileList.resize (argc - 1);
    for(int i = 1; i < argc; ++i)
    {
        fileList[i] = new ofstream(argv[i]);
    }
}

If you only have to write something once to each of those file then use just one ofstream object, open each file, write data, close file, continue the loop.

Note: std::out is NOT needed for ofstream because that is the default behavior.

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

Yes, I agree there are lots of potential problems and pitfalls serializing c++ classes. If the class contains pointers to other objects than serializing becomes much more complex and difficult.

>>fileName.seekg( ( ObjectOfPersonnel.getID() - 1 ) * sizeof ( Personnel) );

That MIGHT work if the ID numbers are sequential and start with 1.

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

C++ also supports malloc(), although you are right in that new is preferrable.

For typecasing malloc(), please read this. Need to include stdlib.h to correct the warning, not do a typecast.

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

Or just convert to int, add one, then convert back to string, as previously suggested

char phone[] = "0000000";
int ph = atol(phone)+1;
sprintf(phone,"%08d", ph);
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>warning: assignment makes pointer from integer without a cast
You are compiling it as C++. Change the file extension to *.c and you will not get that warning.

you still have not fixed the error on line 8. int i, j, **randno, arraywidth, arrayheight; Go back and re-read the code I previously posted. Your code is still incorrect.

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

>>// TYPECAST THE OUTPUT OF MALLOC

Not in C language. C++ requires the typecase but C does not.

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

gets() is NEVER safe to use because it can corrupt the memory of your program and cause it to crash (or coredump in *nix). Read this explaination.

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

That error means it can not find the function cpu_features_init() in any of the file it compiled or in any of the libraries it is trying to link.

Check out those warnings -- they might actually be errors which are causing that link problem.

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

1) It can be used in either text or binary, but most often used in binary files. Not very meaningful in text files.

2) The type]/b] is the object that is store in the file. For example, lets say you saved a bunsh of Personnel c++ classes, then it would be sizeof(Personnel) . If the file is binary file and contains integers, then sizeof(int) In your example, number is the quantity of Personnel records you want to search for. If you want to set the file stream pointer to the 10th Personnel record then number will be 10.

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

you probably want vector<ofstream> fileList; Now all you have to do is loop through the names and open the files, something like this:

vector<ofstream fileList;
fileList.resize(argc-1); 
for(int i = 1; i < argc; i++)
{
    fileList[i].open(argv[i]);
}

Now to write something to all the files just use another loop similar to the above.

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

char *str = new char();

Do you really mean something like char *str = new char(Size); so that more than 1 character is allocated???

Can't really tell much from the code you posted because there are several undefined variables -- such as temp.

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

There are probably several ways to do it, but I would use the string search feature of std::string class

std::string line = "<FILE_NAME>Testfile.dat</FILE_NAME>";
std::string filename;
size_t pos;

if( (pos = line.find("<FILE_NAME>") > string::npos)
{
    filename = line.substr(pos+11);
    // truncate the </FILE_NAME> tag
    pos = filename.find('<'); 
    filename = filename.substr(0, pos);
}
Comatose commented: Very Nice +9
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>lint 9: *randno[j],

That is not leagal way to declare an array because i and j must be constants. What you have are two uninitialized integers.

If you want to declare a two-dimensional array of integers but you don't know how many rows and columns then declare it with a double star like this: int ** randno = 0; Now, to allocate both dimensions

arraysize = 100; // number of rows
randno = malloc(arraysize * sizeof(int *)); // allocate array of pointers
//
// now allocate the columns for each row
for(i = 0; i < arraysize; i++)
{
    randno[i] = malloc(10 * sizeof(int)); // each row has 10 integers
}
Alibeg commented: Straight in center +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>vector<double> a(5);
That creates an array of 5 doubles.

>> a.push_back(1.2);
That adds an additional element to the array, so after this line executes the array will have 6 elements.

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

>>fin >> myArray

The >> operator will stop reading at the first space or tab. If you want the entire line then use getline(fihn.myArray);

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

wxWidgets and OpenGL -- google for them.

Salem commented: cool efficiency +27
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The first problem is line 25 -- count the ( and ) pairs. line 28 and 31 have the same problem if ( (hours<3) && (hours>0) )

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

After about two years this is the best I have managed

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

I get it on occasion.

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

spanking is one thing -- and ok. beating is quite another and punishable by some prison time. Parents who have a hard time distinguishing between the two need some serious time with a head shrink.

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

i change my password now, ^_^

.

I would hope so -- that was probably the dumbest thing I have ever seen posted here at DaniWeb since I first joined. Why didn't you just open your wallet and toss all your money out into the street?

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

Lots of them here

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

why not just #deifne Greeting "HI"

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

> Your home planet is: Silbob Silbob
Howdy neighbour :)

Yup, I live there too :) So far Dude is the only odd ball here.

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

Very good :)

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

I did what you said and changed the constructor so it takes no values but i still get errors

Also i need the constructor to take an initial value

you can have as many constructors as you like.

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

Yes I agree -- we have always been prunish about sex on tv. And I don't know why that commercial was banned here either. I though it was pretty funny -- a little like Benny Hill would do if he were still alive :) :)

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

write the rest of the program and you will find where you need to call that function. The last thing you did in main() was to get keyboard input for the sentence. How you have to run that sentence through the CheckWord() function.

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

Ask your teacher for homework ?? Or you could read through all the threads on this board and try to do the assignments yourself.

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

Apparently your program is never calling CheckWord() because if it did that function would always fail to find the word for the reasons I have already mentioned twice and will not repeat any more.

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

Just as I suspected -- the array dic in CheckWord() is NOT the same as declared in main(). Delete the dic array in CheckWord() and pass the array as a parameter like you did with other functions.

getWord() -- reverse the last two lines so that the file is closed before returning from the function.

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

I never figured out how to use Dev-C++ debugger either -- I always use VC++ because it has such a great debugger. In your programs you may have to use two debugging sessions -- one for client and another for server. With VC++ I've done that successfully quite a few times.

As for your problem: Sorry, but I have no idea what's wrong.

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

Then apparently the dic array is not declared in that function like you posted? In that case, just ignore me :)

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

If you download one of the project and look at the code it will show you the win32 api functions they call.

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

If there is a file then why isn't that program reading it into the array?

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

Don't know what the problem is. Use your compiler's debugger and single-step through the code. Maybe it has a problem with the "/IM" parameter. Maybe that parameter should follow notepad.exe.

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

did you see some of these articles?

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

The array dic does not contain any words, it is nothing more or less than an uninitialized two-dimensional array -- that doesn't contain anything. Before you can use that array you have to put some words into it. Where do those words come from? My guess would be a file that contains a bunch of dictionary words.

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

>>SavingsAccount.hpp(9) : error C2512: 'Account' : no appropiate default constructor available

That means Account needs a constructor that takes no parameters.

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

Below is some code I got from CodeGuru

#include <iostream>
#include <string>
#include <winsock2.h>
using namespace std;
#pragma warning(disable: 4996)

string hostn()
{
char szHostName[128];
std::string str;

if( gethostname(szHostName, sizeof(szHostName)) == 0 )
{
	// Get host adresses
	struct hostent * pHost;
	int i;

	pHost = gethostbyname(szHostName);

	for( i = 0; pHost!= NULL && pHost->h_addr_list[i]!= NULL; i++ )
 	{
 		int j;

 		for( j = 0; j < pHost->h_length; j++ )
 		{
 			if( j > 0 )
 				str += ".";
            char addr[18];
 			sprintf(addr,"%u", (unsigned int)((unsigned
		 	char*)pHost->h_addr_list[i])[j]);
			str += addr;
 		}
  		// str now contains one local IP address - do whatever you want to do with it (probably add it to a list)

 	}
}
    return str;
}


int main()
{
    char name[255] = {0};
    WSADATA wsaData;
    WORD version;
    int error;

    version = MAKEWORD( 2, 0 );

    error = WSAStartup( version, &wsaData );

    std::string s = hostn();

    cout << s << "\n";
    WSACleanup();
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Now of course that function has the problem is populating the dictionary array. Where is it getting the strings from? I would suggest that dic array be declared and populated in main() then passed to CheckWord() as another parameter so that it doesn't have to be populated each time CheckWord() is called.

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

If you can change the content of the input file, change the ls command to report file names only. That would greatly simplify your program.

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

What errors do you get? You only posted code snippet so its not possible for us to compile/test your code.

you declared dic but never filled it with anything. So how in the world do you expect that loop to find a word in the dictionary?

Why don't you just use standard C function strcmp() instead of that loop? (maybe your instructor won't let you??)

You need a different loop to loop through each of the strings in dic

for(k = 0; k < W; k++)
{
     if( strcmp(dic[k], ch) == 0)
     {
           // found it, so now do something here
    }
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I didn't bother to memorize them -- let VC compiler generate them. Although I admit I would use MFC wxWidgets instead of pure win32 api.

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

you can't and we don't either.

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

I don't bother to read them, but I certainly will now :)

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

start here. Sadly, we can't do a lot for you if you don't have your text book, unless you can remember how to program.

int main()
{
    // your code goes here
}