Пят Май 30 1997, 02:25. I'm sitting, programming and thinking: let's write
to Steven.
Write.
Сpд Май 28 1997 16:15, Steven Dyck отписал к All:
SD> 1. I have this program that always gives me a warning and I was
SD> wondering if there was a way to get rid of the warning. #include
SD>
SD> main()
SD> {
SD> unsigned char Monster_Name;
^^ error at this plase. "Bear" is the string constant,
not char constant. You must declare variable for it like this:
unsigned char MosterName[10]; // 10 -- max length of string + 1,
which // will put in this variable;
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
Does this programm work correctly?
SD> Any ideas how to get rid of this? I know it doesn't hurt the
SD> program, but when you have 20 or so of them, it gets anoying.
SD> My next question is how do you use dos commands in C++. I mean
SD> if I wanted to make a program that could show all the files in a
SD> certain directory, or make directories, etc. how would I do this?
See help on header files "dos.h", "io.h", "dir.h". All of dos function
must discribe in ones.
SD> My last question is this. How do you save to a seperate file
SD> (name of person, age, other information), and how do you retrieve
SD> this information in the same program?
Use structs, like this:
typedef struct
{
char Name[20];
int Age;
char MiscInfo[20];
} TPresone;
For write it to file use following construction:
......
TPersone Pers;
FILE * OutFile;
OutFile = fopen("filename","wb");
// cheking for correct open.
fwrite(&Pers,1,sizeof(Pers),OutFile);
.......
fclose(OutFile);
For reading operations use this (or like this) construction:
............
TPresone Pers;
FILE * InFile;
InFile = fopen("filename","rb");
fread(&Pers,1,sizeof(Pers),InFile);
..............
fclose(InFile);
Commander Wolf
If translator does not find bugs in programm, call to system programmer,
hi will find bugs in translator.
--- 2.50+
---------------
* Origin: *) Commander Wolf (* Moscow, Russia (2:5020/760.14)
|