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

>>The only file that is mine out of those errors is time.h

name your heder file something else because your header file named time.h is most likely conflicting with the standard heder file time.h. namespaces do not resolve conflicts of file names.

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

When LoadLibrary() fails, call GetLastError() to get the error number, then FormatMessage() to format the error message string.

DWORD dwError = GetLastError();
char buf[255];
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, 0, dwError,0,
    buf, sizeof(buf));
cout << buf << '\n';
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Must be a problem the way you created the project because I added all three files to a project in Code::Blocks and it compiled without error. Also worked with VC++ 2008 Express.

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

I have not seen a football game (EU version, not American) since mid 1970s when I was stationed at RAF Mildenhall, Englahd. At that time it was just as much fun watching the fans get into big fights as it was watching the game. Do the fans still do that???

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

You are right -- but that may not be the problem.
This works

int main()
{
     unsigned int sz(1073741825);
     std::string str;
     str.resize(sz);
     cout << "Done\n";
     cin.get();

}

But this does not

int main()
{
     unsigned int sz(1073741825);
     unsigned int i = 0;
     std::string str;
     for(i = 0; i < sz; i+= 10)
         str += "xxxxxxxxxx";
     cout << "Done\n";
     cin.get();

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

The "problem" is more than likely too many button controls :icon_eek: Maybe you need to redesign the project so that it doesn't contain so many controls.

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

And, why do I always have to use fgets, and not only instead of gets?
Do you want me to replace all the scanf with fgets?

both scanf("%s" ...) and gets() will let you enter more characters into the buffer than the buffer will hold. Also, if the name you want to enter contains a space then neither function will allow that.

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

Actually the OP tries to get ~2 GBs .. I think you missed ...

std::string str(memblock, sz); //too much for visio :(

Unless I'm missing something line 12 sets the value of sz to 1 Gig. All that line does is initialize str to the first sz bytes of memblock.

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

One possibility is to learn SQL so that you can use SQL databases (such as MS SQL, Oracle, and Sybase) in your C and C++ programs.

Another is to learn how to use sockets (WinSock on MS-Windows) so that your program can communicate with other programs running on either the same computer or another computer across a network.

The possibilities are endless.

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

>>Since you are trying to allocate rather huge amounts of memory (2GB),

Nope. Its only 1 Gig which is less than what st::string.max_size() returns.

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

line 26: strcat() requires the second argument to be const char*, not your string class. But that's easy to fix, just strcat(s, t.s) .

line 34: the problem is on line 33, not line 34. Look carefully at line 33 and you should be able to see the error.

>>but my main function is not included in class
It was in your original post. I see you added the }; that was missing from that class.

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

name your class something else because string is already a class in <string> header file.

line 10: That sure is a waste of time to call strcpy() with an empty string. All you have to do is this: s[0] = '\0'; line 25: delete the string:: part because its not needed when defined inside the class.


line 33: what is main doing there? Its inside the c++ class declaration. I suppose you probably meant that to be int main() function. If that is currect then you don't have a closing } for the class.

You might also want to set your compiler's IDE to use spaces instead of tabs so that they look the same on all IDE's and web browsers.

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

I get the same behavior. I have a Windows 7 64-bit computer with 5 Gig RAM. I also just tried the resize() method and that doesn't work either. Possibly the program can not find enough consecutive memory for that size.

Code::Blocks doesn't like that either -- it throws an error.

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

>>if (option == "enter") {
You can not compare strings like that in C programs. use if( stramp(option, "enter") == 0) { >> tell me what header I have to use for 'fgets'?
stdio.h

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

google for them? UNICODE means the program is being compiled for UNICODE strings, such as using wchar_t instead of char. _x86_ means the processor is one of the 80x88 family of processors (Intel or compatible). _linux should be fairly obvious (os name).

As for the other flags, they will depend on the program being compiled or the library(s) being used.

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

I compiled it with VC++ 2008 Express and only got an error about the first parameter to MTCSInitSystem().

Note that iostream.h is not supported any more (deprecated) by modern compilers. Only ancient compilers such as Turbo C use that header file.

#include<iostream>
#include "MTCSApi.h"
using namespace std;

int main()
{
/* The actual call to the function contained in the dll */ 
int ReturnVal = MTCSInitSystem('0', 0x152a, 0x8220); 
cout<<"The value"<<ReturnVal;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Without seeing the contents of MTCSApi.h I have no clue what the problem is, other than the error message you posted.

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

line 12: that will only read one character, not the entire string. Call fgets() if you want to read the entire line, including spaces fgets(a, sizeof(a, stdin) ); line 13: Q: what is the value of variable i? A: Undefined because it was never initialized to anything.

line 19: %s wants a pointer to a string, but you are passing an integer. Pay more attention to the type of variables you pass to printf().

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

can you give me a compiler like turbo c? i want to become a programmer someday

I don't have to 'give' you one -- you can download it yourself. Get either Code::Blocks or VC++ 2008 Express. Google for them and you will find the download links.

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

I've never seen a Windows application that used 3d Forms :idea:

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

AD, you always have the answer to the questions, AND THEY ARE RIGHT!! Thanks so much, it compiled. But now a new issue has showed up, in Puzzle.cpp, the overloaded operator<< is declared as a friend in the .h file but the .cpp is saying it is not able to access the private variables. Any suggestions?

Yes -- you have to make that parameter const reference too in the *.cpp implementation file.

Also, AD, can you please tell me why it did not work the way, why it needs to have the namespace declared, it might be of use to people like me.

namepsaces always have to be declared. There are at least three ways to do that, which you probably already know.

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

Welcome to DaniWeb. Where are you from anyway? Never heard of the name Nidhi before.

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

Welcome to DaniWeb.

I'm constantly getting into trouble by chosing options that I have no idea of what they do or what they are for.

That happens to me too :)

Presently I'm making a mess trying to concoct a network using Win2K and WinXP . Soon I may try intoducing Win7 into the fray.

Windows 7 installation will do all that for you now, at least it did on my home network, but I only have Win7 installed on all my home computers.

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

Weeeeeeelllllllccccccoooooommmmmeeeee! Hope you enjoy your stay here.

nav33n commented: Heh! +0
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I started out with a temp agency here in St Louis in 1986/7. At the time I had zero programming experience, not even college degree. My sole assets were that I was about 43 years old, recently retired US military, bought an Intro to C programming book and cheap computer, then studied that book for a few weeks. I saw an ad in the local newspaper for an entry level job, applied for it, and was hired.

I could be wrong but I suppose there are still a few entry-level jobs like that for us normal-brained folks.

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

There are two main problems:
1) >> friend ostream &operator<<(ostream &os, const Puzzle& p);
The last parameter should be passed by reference, not by value. Also change that in the *.cpp implementation file.

2) in Puzzle.h you need to declare the namespaces, such as

#include <fstream>
using std::fstream;
using std::ifstream;
using std::ofstream;
using std::ostream;

or just add std::fstream before each occurence of the c++ class.

sid78669 commented: If there is an answer, Ancient Dragon has it!! +2
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Well im making my first somewhat useful GUI program, and Ive only been with win32 for about a month now ( C/C++ for maybe 7+ ish months )

Congratulations. There's about a year's learning curve before you get really good at it.

People who do systems program have no need for win32. There are a lot of programs that do not require GUI, console, or human interaction.

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

change %d go %u (unsigned int) or typecast the size into an int, which could produce unexpected results if the file size is larger than an int can hold.

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

>>Any ideas what is it that I'm missing?

Yes -- if you are using MS-Windows or *nix operating systems than that will not work because your program can not change the memory values of memory it does not own. You can't just plug some random memory location into your program.

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

>>How to do fancy stuffs using C/C++?

Go to www.codeproject.com and there you will find hundreds of programs/tutorials that do fancy stuff.

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

This is your lucky day -- I gave you positive instead of negative rep for bumping a 4-year-old thread

If you only read one byte into a 4-byte integer that would make the integer not worth shit. You can't do it like that (at least so that it will produce a valid integer). First read the byte into a char variable, then typecast the char into the integer. The sizeof operator will still work because sizeof(char) = 1.

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

Store the data in a hidden file or if *nix a read-only file. You could also use an encrypted file. There is nothing that will be 100% tamper-proof.

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

There is no difference because C compiler normally ignore spaces. You can code it either way unless your instructor (assuming you are a student) or other coding standards say otherwised.

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

This works, even if you later want to change the type of the array, say from char to int:

length_of_array = sizeof(array)/sizeof(array[0]);

That doesn't work when the array is a parameter to a function

void foo(int ay[5])
{
int length_of_array = sizeof(ay)/sizeof(ay[0]);
printf("%d\n", length_of_array);
printf("sizeof(ay) = %d\n" ,sizeof(ay) );
printf("sizeof(ay[0]) = %d\n",sizeof(ay[0]));

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

Most of us can probably do that, but we are not in your classroom. Post whatever you have done to solve that problem and ask questions. The first things you need to do is listen in class (assuming you attended class at all), then study your textbook.

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

See the win32 api function GetOpenFileName() here and here.

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

what version of Windows are you running?

Unregister that ActiveX control and try to open the file again. If it works then there is probably something wrong with that ActiveX control.

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

Why do you have to convert those C functions at all? Just call them norally in any c++ code you want to add to the project and leave the C code in tact.

In the c++ files you just have to add this: probably add it in the header file that contains the function prototypes of all those C functions. This is the same method that compiler writers use in standard header files so that the same header files can be used in both C and C++ programs.

#ifdef _cplusplus
extern "C"
{
#endif
    // now prototype all those C functions
#ifdef _cplusplus
}
#endif
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Is the ptr a NULL value?? No. Well just like any other invalid pointer the program doesn't know its invalid until delete attempts to delete it. You will get the same behavior if you try to delete any pointer, whether its a c++ class or not. You wrote the delete ptr; code, not the compiler. So if its wrong its your fault, not the compiler's. There is nothing about that pointer that would indicate the object has already been destroyed. When a c++ class is deleted only the data section of the class is destroyed, not the code section. As long as the code does not attempt to reference any of the class's data it should still work (undefined behavior though).

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

Will type casts work?
i.e. [b](const char *)[/b]results.st_size This should enable it to compile, but honestly, I suspect you'll get invalid results.

Of course typecase will NOT work. You can not typecast an int into char* because it has to be converted. Very similar to the original post but use results.sz_size instead of the result value from stat() function.

struct stat results;
char buf[40];
stat(pname, &results);
sprintf(buf,"%d", results.st_size);
write(1,buf, strlen(buf));
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>in your case a query like site:www.daniweb.com "free online television"

Hum ... never new we could do that :)

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

vc++ 2008 Express produces a runtime error on that delete ptr; line because the class instance was already deleted. I've seen a few class objects delete themselves -- such as Microsoft's COM functions.

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

If you want to program Windows Forms why in the world would you want to use DirectX???

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

Most programs will use the Microsoft Treeview Control. Here is some sample code. The treeview control generates an OnClick event and one of its parameters is the node that was clicked.

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

I suppose one way to do it would be to create an array of 101 characters, each array element represents the numeric grade. The use the grade to index into that array. For example

char grades[101] = {0};
grades[100] = grades[99] = grades[98] = 
    grades[97] = grades[96] = grades[95] = 'A';
grades[94] = grades[93] = grades[92] = 
    grades[91] = grades[90] = 'B';

// now get the grade
int score = 93;
char gr = grades[score];
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>ompare every character with \ and then add another one but it would be too slow,

HOW MANY TIMES DO WE HAVE TO TELL YOU WHAT YOU DO NOT HAVE TO DO THAT!!! :@

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

You are assuming everyone knows that SHOP, BFS, and TLE mean. We don't. You might get more help if you would provide links to that.

Also, that appears to be a C program, not C++.

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

Ok guys, I understand that I need to use double \\, but for example, if I have an txt file - 1.txt, in wich is "C:\Users\2.txt", and if I read that(C:\Users\2.txt) and save it to -string[20]={C:\Users\2.txt}, how could I open that file using identifier string(not C:\Users\2.txt)?
PS. I dont know what is in 1.txt, it could be any file, so I cant manually add one more slash.

All you have to do is read the line into a string object then pass that to open(). As Walt explained before the \\ issue only occurs in string literals -- text between quotes such as "c:\\" It does NOT apply to strings that are read from a data file or from the keyboard.

// open the file created by the dir command
ifstream in("i.txt");
std::string
// read a line from that file
getline(in, string);
// use the contents of that string
// to open another file.
ifstream in2(string.c_str());
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Yes you do. The command above will list files starting with the current directory -- probably from the location of the .exe file. system("dir c:\\ /s > c.txt"); will start listing from the root directory.

You are right -- I thought it worked, but all it gave me was a list of the current directory.

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

If you want a list of all the files on your he you don't need the \ character at all. Just this: system("dir c: /s > c.txt");