你好我有一个奇怪的问题sprintf
。这是我的代码:
void draw_number(int number,int height,int xpos,int ypos){
char string_buffer[5]; //5000 is the maximum score, hence 4 characters plus null character equals 5
printf("Number - %i\n",number);
sprintf(string_buffer,"%i",number); //Get string
printf("String - %s\n",string_buffer);
int y_down = ypos + height;
for (int x = 0; x < 5; x++) {
char character = string_buffer[x];
if(character == NULL){ //Blank characters occur at the end of the number from spintf. Testing with NULL works
break;
}
int x_left = xpos+height*x;
int x_right = x_left+height;
GLfloat vertices[] = {x_left,ypos,x_right,ypos,x_left,y_down,x_right,y_down};
rectangle2d(vertices, number_textures[atoi(strcat(&character,"\0"))], full_texture_texcoords);
}
}
通过printf
那里的呼叫,成功打印数字并按预期绘制数字。当我把它们拿走时,我当然无法查看输出并进行比较,但是数字没有正确呈现。我假设sprintf
以某种方式中断。
这也发生在NSLog
. 在程序的任何地方添加NSLog
' 都可以破坏或修复该功能。
到底是怎么回事?
这是在 iOS 4 SDK 中使用 Objective-C。
谢谢你的任何回答。