Question about printing char's
I have a directx program where I want to read text in from a file and print on the screen. The function Im using takes a
char * and prints it on the screen. Heres my code
char *c;
ifstream story_in(*file);
if (!story_in)
exit(0);
for ( i = 0; i < 10; i++)
{
story_in >> *c;
Draw_Text_GDI(c,x,y,RGB(0,255,0),lpddsprimary);
}
story_in.close();
I never really learned how to use char * so this is wrong. If anyone could point me in the right direction, Id be appreicative, thanks
1) *c is a character so in >> *c will write the first non whitespace character to wherever c points, you want in >> c or more likely
in.getline(c,[size of buffer pointed to by c])
2) god only knows where c points in your code, but it probibly ain''t gonna like it.
change
char *c to
char c[256] or char *c = malloc(256) (then free(c) when you are done)
or, use the string class
string s;
...
getline(in,s);
Draw_Text_GDI(s.c_str(),x,y,RGB(0,255,0),lpddsprimary);
also you ain''t changeing x and y so each string is going to overwrite the last one.
in.getline(c,[size of buffer pointed to by c])
2) god only knows where c points in your code, but it probibly ain''t gonna like it.
change
char *c to
char c[256] or char *c = malloc(256) (then free(c) when you are done)
or, use the string class
string s;
...
getline(in,s);
Draw_Text_GDI(s.c_str(),x,y,RGB(0,255,0),lpddsprimary);
also you ain''t changeing x and y so each string is going to overwrite the last one.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement