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

Those errors mean you either failed to code those functions or you didn't include the *.o file in the makefile.

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

>>The great thing about this project is that there isn't anything that has to do with MS-Excel at all in the spreadsheets I'm working with.

You are not working with xls files as you initially stated, but comma separated csv file. The first line contains cell titles while the remaing lines contain the data.

use getline() to read each line, ignoring the first line read. After that use getline() in conjunction with stingstream to extract second colum, Something like this:

string line;
ifstream in("fiulename.csv");
getline(in, line); // ignore cell titles
while( getline(in, line) )
{
    float n;
    stringstream str(line);
    while( getline( str, line, ',') )
    {
        n = atof( line.c_str());

       // instead of atof() you could also convert string to float
       // using another stringstream object, like this:
       stringstream str1(line);
       str1 >> n;
       // now do thatever you want with this cell value
   }
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I like M$ compilers because of its excellent debugging. You can debug anything that you write, including DLLs, windows services, and COM programs. By debug I mean it will let you single step through a program one line at a time and view the value of all know variables as well as see the order of program execution. That alone is worth the cost of VC++ (any edition) to the professional programmer whose time is very important.

tux4life commented: Yes, the debugging is really good, I like it too :) +11
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I believe most programs contain language-specific dlls for each of the languages they wish to support. If its a MS-Windows gui program then put all the resources in language-specific dll.

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

You didn't mention the compiler you are using, but assuming it is VC++ 2008 (Express)

Select menu item Project --> Properties --> expand Configuration Properties --> General. In the pane on the right, the third item from the bottom, change "Character Set" option to "Not Set"

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

Dev-C++ is not really recommended any more because it is no longer being updated and is already several years old.

>>i.e. not for beginars.
If you want to spend the $$$ for it, then buy a copy of VC++ 2008 Professional. Borland C++ Builder is also considered pretty good.

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

Should work as long as you are logged into MS-Windows with administrative privileges. If not, then the os may prevent you from writing into c:\\ root directory. Try writing that file to another directory that you know is writable.

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

depends on the thread, but many times execution time is not measurable because it happens too quickly.

But generally you would call time functions when the thread starts and again when it ends, then execution time is the difference between those two times. Call clock() to get time in milliseconds (for most operating systems). On MS-Windows you can use QueryPerformanceCounter()

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

Its almost impossible to read .xls files directly because they contain proprietary MS-Excel data. But if you really really really have to do it then read this document

The simpler solution is to convert the xls files to cvs files using MS-Excell program. The csv files do not contain all that binary data and reading is straight forward.

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

Its not calculating the average score correctly. It should be <sum of all scores> / MAX_SIZE. To do that you need another loop before the one you already have

int sum = 0;
for(int i = 0; i < MAX_SIZE; i++)
   sum += scores[i];
average = sum / MAX_SIZE;

Now delete lines 37 and 38 in the code snippet you posted.

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

put an else between the first two if statements, like you did between the last two statements.

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

Why is contiguous memory even an issue here? Once the array is allocated it doesn't really matter.

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

That was the title of the original thread.

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

fstream auto closes the file when the function is finished, and that's why I didn't do it in main(). But you have to call close() if you wanted to delete the file in the same function that opened it.

Nick Evan commented: Did not know that :) +20
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Please describe the problem -- what does the code not do correctly? Or are there compiler errors, post some of the errors.

And what operating system/compiler are you using?

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

Its not necessary to test for file existance beforehand. Just open like this: ios::in | ios::out | ios::ate . This will append text to the end of the file every time the program is run.

int main(int argc, char* argv[])
{
    fstream out("HelloWorld.txt", ios::in | ios::out | ios::ate );
    if( out.is_open() )
    {
        out << "Hello World\n";
    }
    else
        cout << "Failed\n";
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

post #3 presents a 1d array as if it were a 2d array. Thats a good way to do it, unless of course the requirement is to create a 2d array.

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

I agree we need an MS-Windows programming forum because there are lots of win32 api questions. But in all the time I have been here I don't recall ever having a mobile device question, although I might have missed it.

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

what compiler and version are you using?

Microsoft has a Scribble Tutorial that's an introduction to MFC.

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

>>These files are however *.c and *.h? How do I compile them
use a c compiler, such as gcc (*nix) or one of the many c compilers available on ms-windows.

Who to use them once compiled? I have not the slightest clue.

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

>>for(i=0;i<=d-1;i++)
Why not just i < d to avoid subtracting 1 from d on every loop iteration.

And it might be better to use another counter intead of all those subtractions. Note also that you don't need the str2 variable.

int x;
x = strlen(str) - 1;
for(i = 0; flag == 0 && i < d; i++, x--)
{
   if( str[i] != str[x] )
   {
       flag = 1;
   }
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Argentine ants living in vast numbers across Europe, the US and Japan belong to the same inter-related colony, and will refuse to fight one another.

Its unfortunate that humans are not like that.

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

hi guys ;

i have a code for read txt and later write to sql database but its not working :( can you help me _?

When you need your car repair do you take it to a garage and tell the repairman "my car is broke, pleas fix it" ? Of course you don't -- you explain as well as you can what's wrong with it.

We are the same way. Don't just post a bunch of code and tell us "My code is broke". You have to tell us what is wrong with it, why do you think it doesn't do whatever its supposed to do. does it not compile? Then post some of the compile errors/warnings. Does it produce the wrong output? Then post the output.

sknake commented: so true +3
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

line 11 of that code snippet is wrong. It should be delete[], not delete.

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

dont rlly know...told ya i am noob in this thing

You will have to get that library before you can attempt to compile the program you posted. google for it and see if that will find it.

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

Hey AD, in your post (#3) you forgot a bracket on this line: while( fin.read( iobuffer, sizeof(iobuffer) ) :P

Nobody is perfect :)

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


another question is.. how will it affect my client.exe? i don't really know what to expect once you run the programs. please explain?

It won't affect it at all -- just put the blank line at the end of the file like the warning message asked you to do.

I'm surprised there are still compilers that produce that warning message. I haven't seen it in more than 15 years.

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

When I actually tried it I had the same problem. I used a command prompt and found out that the two files were just a few bytes different.

well, the code I posted almost works. The problem is that the last few bytes does not get read/written

int main(int argc, char* argv[])
{
    char iobuf[255];
    size_t total = 0;
    size_t sz = 0;
    ifstream fin("file1.doc", ios::binary);
    if( !fin.is_open() )
    {
        cout << "Can't open the file\n";
        return 1;
    }
    ofstream fout( "copy.doc", ios::binary);
    while( fin.read(iobuf, sizeof(iobuf) ))
    {
        sz = fin.gcount();
        total += sz;
        fout.write(iobuf, sz);
        sz = 0;
    }
    sz = fin.gcount();
    if( sz > 0)
    {
        cout << "sz = " << sz << "\n";
        total += sz;
        fout.write(iobuf, sz);
    }
    fin.close();
    fout.close();
    cout << "Total = " << total << "\n";
	return 0;
}
tux4life commented: Good code :) +11
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I missed this reply - sorry. I am treating the microsoft word doc in the C++ code as a binary doc and using fstreams to read/write the data. Then when I use microsoft word to open the newly copied file, the contents are not readable.
Is it possible to just read the contents of the microsoft doc file in binary form, write and open without doing any formatting of special chars?

That is exactly what the code snipped I posted will do. Its just standard file i/o operation, nothing special about it.

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

>>Does one need to use microsoft apis to ensure that non-ascii chars are converted?

Huh? I didn't post anything specific to microsoft, only standard C++ stuff. Binary files have to be opened in binary mode using ios::binary option. If you don't do that then the destination file will be corrupt.

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

MS-Windows COM programming uses a structure called a VARIANT that might be usefule to you. It has two members: a union of different data types, and an integer that indicates the kind of data was put in the union. It would look like this:

struct data
{
     int type;
     union
     {
          std::string str;
          float fl;
     };
};

With that you could have your function return any kind of data you want. I would recommend the function is passed the vector by reference to avoid all the complications of duplication that exists when its used as the return value.

bool foo( vector<struct data>& aList, string typeConversion )
{
   // fill in the vector
   // then return either true or false
   // depending on success or failure of this function
   return true;
};

int main()
{
    vector<struct data> aList;
    foo(aList, "123 456");
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>When I try to open the newly created file, the contents are not readable
Its because doc files are binary files, not text files. Those files contain a lot of formatting information, such as font, font color, font size, etc, that is only readable by MS-Word or similar compatible program.

Binary files have to be opened in binary mode ifstream fin(file, ios::binary); and use stream's read() method.

ifstream fin(file, ios::binary);
ofstream out("newfile.doc", ios::binary);
char iobuffer[255];
while( fin.read( iobuffer, sizeof(iobuffer) )
{
    // do something with this block of data
    size_t sz = fin.gcount();
    out.write( iobuffer, sz);
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

No -- that's a very unique water tower. Every town (village) in our area has one. Below is the common shape around here. In Suffolk UK someone actually made a house out of one. http://en.wikipedia.org/wiki/Water_tower

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

This is not very far from where I live -- 170 ft water tower built in 1949 and restored in 1995.
http://www.catsupbottle.com/

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

Well sorry for trying to help. :'(

I didn't mean to say there is anything at all wrong with multiple reports, just thought it would save everyone the bother of reporting unnecessarily.

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

When a post is flagged is it possible to disable that link so that others know it has already been reported ? Currently there is no way for members to know if a post has been reported or not, so we wind up with several people reporting them.

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

Don't feel too bad -- most of us were in your shoes. There is a sticky thread about additional c++ books you might want to read. If you have a few specific questions then just post them here.

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

I downloaded that zip file and tried to compile it with VC++ 2008 Express but some errors on bncsutil library (its not on my computer). Where do I get it ?

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

he told me to post the whole program so he can try to compile it...welll the whole programe has 18MB

Go back and re-read my post. I said to delete all compiler-generated files.

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

Your code doesn't compile. The compiler hates the line I commented out below.

Yatzy::Yatzy() //Konstruktor
{
	mNbrPlayers.clear();
//	mNbrPlayers.push_back(YatzyPlayer());
	
}

The problem is in operator= method. You need to make the parameter const YatzyPlayer& operator=(const YatzyPlayer& o);

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

>>vector<int> YatzyPlayer::getResults()

That function should return a reference to the vector, not a copy of it. vector<int>& YatzyPlayer::getResults() See the reference operator &

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

zip up the entire project and attach it to your post so that we can try to compile/link it ourselves. Please delete all compiler-generated files, such as *.obj and *.ncb to that the zip file is smaller.

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

search www.codeproject.com because I've seen several articles about that.

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

The links are working now and I'm currently installing it.

[edit]Ok, download and install finished. SHGetKnownFolderPath() is in that header file. So if you want to use that function then you need to download and install that sdk too.

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

http://msdn.microsoft.com/en-us/library/96ayss4b(VS.80).aspx

I think the example in that page might help you out !

Also pay close attention to the Note in that article -- you can not use popen() in a Windows program, it only works in console programs. And that's really unfortunate.:'(

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

There is a message in that compile.txt file that states it must be compiled with VC++ 2008 (probably express edition will be ok).

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

According to MSDN the function is supposed to be in shlobj.h, but it isn't there in my version of the WPSDK. Since that is a Vista only function then it has to be in the Vista update to the SDK.

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

I think you will need to Vista update to the Windows Platform SDK. I just tried to get it but kept getting link errors, so I don't know what's going on unless the M$ site is just too busy at the moment.

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

maybe this article will help you

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

check out this article. I'm not sure it will help you, but it almost has to contain ability to open/close the DVD door.