Advertisement

lesson 13 problem

Started by December 03, 2001 03:02 PM
3 comments, last by soreno 23 years, 2 months ago
Lesson13 (wgl font tut..) in "int DrawGLScene(GLvoid)": .. glRasterPos2f(-0.45f+0.05f*float(cos(cnt1)), 0.32f*float(sin(cnt2))); char* test="test"; //my code strcat(test, "-"); //my code glPrint(test); //my code cnt1+=0.051f; .. "test----" is displayed on screen, why not "test-"?
Try doing strcpy(test,"test") instead of directly assigning the string.
Advertisement
it works.. but why? whats wrong with assigning direct?
As I see it, when you assign a value directly, it doesn''t change the length of the array. But when you do strcpy(), it resizes the character array to the length of the string being copied.
You can try freeing the array manually, and then assigning the new value directly, it should give the same result. But in practice try to stick to the available string functions.
first off you should never cpy strings into arrays that are not big enough to hold the entire string. since you are corrupting other pieces of memeory which can lead to protection faults or worse just screw up important varibles and keep you confused why things dont work when they should.

This topic is closed to new replies.

Advertisement