Keil中for(int i=0;;)报错

一、报错

二、报错原因 

定义变量i报错

这是C++的写法,C语言不支持

用C语言格式应该为

int i=0;

for(int i=;;;)

{}

c99支持第一种写法,如果使用gcc,可以指定c99模式。

三、指定c99模式

``` #include <stdio.h> #include <stdint.h> #include <stdlib.h> typedef struct { uint8_t rows[8]; } Frame; // 生成表情帧数据,直接填充数组 void generate_emojis(Frame* frames) { // 定义四种表情模板 const Frame smile = {{ 0b00111100, // 笑脸 0b01000010, 0b10100101, 0b10000001, 0b10100101, 0b10011001, 0b01000010, 0b00111100 }}; const Frame cry = {{ 0b00111100, // 哭脸 0b01000010, 0b10100101, 0b10000001, 0b10011001, 0b10100101, 0b01000010, 0b00111100 }}; const Frame heart = {{ 0b00000000, // 爱心 0b01100110, 0b11111111, 0b11111111, 0b01111110, 0b00111100, 0b00011000, 0b00000000 }}; const Frame sun = {{ 0b00100100, // 太阳 0b00100100, 0b11011011, 0b01111110, 0b00111100, 0b01111110, 0b11011011, 0b00100100 }}; // 填充88帧数据 for (int i = 0; i < 88; ++i) { switch(i % 4) { case 0: frames[i] = smile; break; case 1: frames[i] = cry; break; case 2: frames[i] = heart; break; case 3: frames[i] = sun; break; } } } int main(void) { Frame emojis[88]; // 固定大小数组替代vector generate_emojis(emojis); FILE* file = fopen("animation.bin", "wb"); if (!file) { fprintf(stderr, "文件创建失败!\n"); return EXIT_FAILURE; } // 验证帧数 printf("实际生成帧数: %d\n", (int)(sizeof(emojis)/sizeof(Frame))); // 写入所有帧数据 for (int i = 0; i < 88; ++i) { fwrite(emojis[i].rows, sizeof(uint8_t), 8, file); } fclose(file); printf("成功生成88帧动画文件!\n"); return EXIT_SUCCESS; }```出现错误:KSDL.c“#include <stdint.h>”: warning C318: can't open file 'stdint.h' KSDL.c“ uint8_t rows[8];”: error C141: syntax error near 'uint8_t', expected 'bit' KSDL.c“ uint8_t rows[8];”: error C129: missing ';' before 'rows'请修改并给出完整代码
最新发布
03-17
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值