TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: STEVEN DYCK
from: THOMAS MAEDER
date: 1997-05-30 17:06:00
subject: Three questions

SD> 1. I have this program that always gives me a warning and I was wond
SD> there was a way to get rid of the warning.
SD> #include 
SD> main()
SD> {
SD> unsigned char Monster_Name;
SD> Monster_Name = "Bear";
SD> clrscr();
SD> printf("%s", Monster_Name);
SD> getch();
SD> return(0);
SD> }
SD> The warning I get is this :
SD> Warning Nonportable pointer conversion in function main
The declaration of Monster_Name is wrong.
unsigned char Monster_Name[];
or
unsigned char *Monster_Name;
And   it's   better   to   directly  initialize  Monster_Name  in  its
declaration:
unsigned char Monster_Name[] = "Bear";
And  since  the  characters  accessed  through   Monster_Name   aren't
modified, it's better to declare them to be constant:
const unsigned char Monster_Name[] = "Bear";
SD> My next question is how do you use dos commands in C++.  I mean if I
SD> make a program that could show all the files in a certain directory,
SD> directories, etc. how would I do this?
You should use a library for this purpose.
SD> My last question is this.  How do you save to a seperate file (name
SD> age, other information), and how do you retrieve this information in
SD> program?
Use file streams. For saving a number, use something like:
const int i = 42; 
ofstream os("outfile.txt");
os << i;
For reading it:
int i; 
ifstream is("outfile.txt");
is >> i;
Thomas
---
 þ MM 1.0 #0113 þ Oops... Tried to steal my own tagline!
---------------
* Origin: McMeier & Son BBS (2:301/138)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.