::> Hello. I am new to this area. I have worked with C++ for almost a year,
The code you posted was C, not C++.
::> unsigned char Monster_Name;
::> Monster_Name = "Bear";
You only set up space for 1 char, you need to set up an array (or a pointer
and allocate space for it).
unsigned char Monster_Name[21]; // Gives you 20 characters + trailing \0
// to work with.
strcpy(Monster_Name, "Bear");
::> printf("%s", Monster_Name);
%s is for a \0 terminated character array, but you passed a single unsigned
char. With the above changes it should work.
::> The warning I get is this :
::> Warning Nonportable pointer conversion in function main
Monster name is type unsigned char, "Bear" is a const char pointer
mplicit).
::> My next question is how do you use dos commands in C++. I mean if I
ante
::> make a program that could show all the files in a certain directory, or
a
::> directories, etc. how would I do this?
look up system() in your help.
::> My last question is this. How do you save to a seperate file (name of
er
::> age, other information), and how do you retrieve this information in the
::> program?
In C++, you'd probably use fstream's.
As for you code sample, let's make it C++ and stay on topic:
::> #include
::> main()
::> {
::> unsigned char Monster_Name;
::> Monster_Name = "Bear";
::> clrscr();
::> printf("%s", Monster_Name);
::> getch();
::> return(0);
::> }
// off top of my head - May contain errors
#include
#include
int main(void)
{
char inkey = 0;
unsigned char *Monster_Name = new unsigned char[21];
strcpy(Monster_Name, "Bear"); //pure C++ enthusiasts might recommend
// strstream's instead
clrscr(); //non-portable?
cout << Monster_Name; //print it
while (!inkey) cin >> inkey; //wait for keypress
delete[] Monster_Name; //clean up
return 0;
}
# Herbert Bushong harchon@centuryinter.net [TEAM OS/2]
- Blackbeard's BBS Intelec: 239:600/0
+ Fido: 1:19/19 http://www.win.net/eunicecity/stltcc/hbush/
---
RM 1.31 2508 * <- Tribble # <- Electrocuted tribble.
---------------
* Origin: Blackbeard's BBS - Ville Platte, LA - 318-468-3385 (1:19/19)
|