对于一个项目,我正在尝试从字符串中读取int和字符串.唯一的问题是sscanf在看到空格时似乎打破了读取%s.反正有没有解决这个限制?这是我正在尝试做的一个例子:
#include<stdio.h>
#include<stdlib.h>
int main(int argc, char** argv) {
int age;
char* buffer;
buffer = malloc(200 * sizeof(char));
sscanf("19 cool kid", "%d %s", &age, buffer);
printf("%s is %d years old\n", buffer, age);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
它的印刷品是:"酷是19岁",我需要"酷孩子19岁".有谁知道如何解决这一问题?
我正在尝试制作一个以恒定帧速率运行的SDL程序.然而,我发现即使我的程序滞后很多并且跳过很多帧(即使它在低帧运行并且渲染不多).
你们有什么建议让我的程序运行得更顺畅吗?
#include "SDL.h"
#include "SDL/SDL_ttf.h"
//in milliseconds
const int FPS = 24;
const int SCREENW = 400;
const int SCREENH = 300;
const int BPP = 32;
void apply_surface(int x, int y, SDL_Surface* source, SDL_Surface* destination) {
SDL_Rect offset;
offset.x = x;
offset.y = y;
if(SDL_BlitSurface(source, NULL, destination, &offset) < 0) {
printf("%s\n", SDL_GetError());
}
}
int main(int argc, char* argv[]) {
//calculate the period
double period = 1.0 / (double)FPS;
period = period * 1000;
int milliPeriod = …Run Code Online (Sandbox Code Playgroud)