C stdio编译错误问题解决及去掉^M符号

16 篇文章 0 订阅
13 篇文章 0 订阅
错误:
GNU C (Sourcery G++ Lite 2009q1-203) version 4.3.3 (arm-none-linux-gnueabi)
        compiled by GNU C version 4.3.2, GMP version 4.2.4, MPFR version 2.3.2.
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: ff2e25870db5a86cad0a49ae0451c7d1
In file included from /opt/arm-2009q1/arm-2009q1/bin/../arm-none-linux-gnueabi/libc/usr/include/stdio.h:75,
                 from client_sock.c:1:
/opt/arm-2009q1/arm-2009q1/bin/../arm-none-linux-gnueabi/libc/usr/include/libio.h:332: error: expected specifier-qualifier-list before 'size_t'
/opt/arm-2009q1/arm-2009q1/bin/../arm-none-linux-gnueabi/libc/usr/include/libio.h:364: error: expected declaration specifiers or '...' before 'size_t'
/opt/arm-2009q1/arm-2009q1/bin/../arm-none-linux-gnueabi/libc/usr/include/libio.h:373: error: expected declaration specifiers or '...' before 'size_t'
/opt/arm-2009q1/arm-2009q1/bin/../arm-none-linux-gnueabi/libc/usr/include/libio.h:493: error: expected '=', ',', ';', 'asm' or '__attribute__' before '_IO_sgetn'
In file included from client_sock.c:1:
/opt/arm-2009q1/arm-2009q1/bin/../arm-none-linux-gnueabi/libc/usr/include/stdio.h:312: error: expected declaration specifiers or '...' before 'size_t'
/opt/arm-2009q1/arm-2009q1/bin/../arm-none-linux-gnueabi/libc/usr/include/stdio.h:319: error: expected declaration specifiers or '...' before 'size_t'
/opt/arm-2009q1/arm-2009q1/bin/../arm-none-linux-gnueabi/libc/usr/include/stdio.h:361: error: expected declaration specifiers or '...' before 'size_t'
/opt/arm-2009q1/arm-2009q1/bin/../arm-none-linux-gnueabi/libc/usr/include/stdio.h:363: error: format string argument not a string type
/opt/arm-2009q1/arm-2009q1/bin/../arm-none-linux-gnueabi/libc/usr/include/stdio.h:365: error: expected declaration specifiers or '...' before 'size_t'
/opt/arm-2009q1/arm-2009q1/bin/../arm-none-linux-gnueabi/libc/usr/include/stdio.h:367: error: format string argument not a string type
/opt/arm-2009q1/arm-2009q1/bin/../arm-none-linux-gnueabi/libc/usr/include/stdio.h:678: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'fread'
/opt/arm-2009q1/arm-2009q1/bin/../arm-none-linux-gnueabi/libc/usr/include/stdio.h:684: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'fwrite'
/opt/arm-2009q1/arm-2009q1/bin/../arm-none-linux-gnueabi/libc/usr/include/stdio.h:706: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'fread_unlocked'
/opt/arm-2009q1/arm-2009q1/bin/../arm-none-linux-gnueabi/libc/usr/include/stdio.h:708: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'fwrite_unlocked'
In file included from client_sock.c:2:
/opt/arm-2009q1/arm-2009q1/bin/../arm-none-linux-gnueabi/libc/usr/include/stdlib.h:140: error: expected '=', ',', ';', 'asm' or '__attribute__' before '__ctype_get_mb_cur_max'
In file included from /opt/arm-2009q1/arm-2009q1/bin/../arm-none-linux-gnueabi/libc/usr/include/sys/select.h:46,
                 from /opt/arm-2009q1/arm-2009q1/bin/../arm-none-linux-gnueabi/libc/usr/include/sys/types.h:220,
                 from /opt/arm-2009q1/arm-2009q1/bin/../arm-none-linux-gnueabi/libc/usr/include/stdlib.h:320,


原因: 代码中有不能识别的字符。如windows下编辑源文件,在Linux下出现^M符号。


去掉^M符号方法:


  find -name \*h -exec sed -i 's/\r//g' {} \;



以下是一个简单的去除多行注释的示例代码(使用C语言编写): ```c #include <stdio.h> void remove_comments(FILE* input_file, FILE* output_file) { int c, prev_c; int in_comment = 0; while ((c = fgetc(input_file)) != EOF) { if (in_comment) { // 如果当前在注释中,则判断是否遇到了注释结束符号 if (prev_c == '*' && c == '/') { in_comment = 0; } } else { // 如果当前不在注释中,则判断是否遇到了注释开始符号 if (prev_c == '/' && c == '*') { in_comment = 1; } else { // 如果当前不在注释中且不是注释符号,则写入输出文件 fputc(prev_c, output_file); } } prev_c = c; } // 写入最后一个字符 fputc(prev_c, output_file); } int main(int argc, char* argv[]) { if (argc != 3) { printf("Usage: %s input_file output_file\n", argv[0]); return 1; } FILE* input_file = fopen(argv[1], "r"); if (input_file == NULL) { printf("Cannot open input file %s\n", argv[1]); return 1; } FILE* output_file = fopen(argv[2], "w"); if (output_file == NULL) { fclose(input_file); printf("Cannot open output file %s\n", argv[2]); return 1; } remove_comments(input_file, output_file); fclose(input_file); fclose(output_file); return 0; } ``` 以上代码使用了一个 `in_comment` 变量来表示当前是否在多行注释中,同时使用 `prev_c` 变量来记录上一个字符。在遍历输入文件时,如果当前在注释中,则判断是否遇到了注释结束符号;如果当前不在注释中,则判断是否遇到了注释开始符号。如果当前不在注释中且不是注释符号,则将上一个字符写入输出文件。 你可以根据需要对代码进行修改和优化,例如增加错误处理、优化读写文件的方式等。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值