“{\rtf1\ansi"错误编译C程序时 [英] Error on "{\rtf1\ansi" when compiling C program

查看:29
本文介绍了“{\rtf1\ansi"错误编译C程序时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#include 主要的(){浮动法尔,摄氏度;int 下、上、步;下 = 0;上 = 300;步 = 20;法尔 = 更低;while (fahr <= upper) {摄氏度 =(5.0/9.0)*(fahr-32.0);printf(%3.0f %6.1f\n",fahr,celsius);法尔 = 法尔 + 步长;}}

我使用的是 mac.在终端中,我使用 gcc -g file.c 进行编译并得到以下错误和警告:

file.c:1:1: 错误:预期标识符或 '('{\rtf1\ansi\ansicpg1252\cocoartf1265\cocoasubrtf190^file.c:21:11: 警告:缺少终止 ' 字符 [-Winvalid-pp-token]printf( \'93%3.0f %6.1f\\n\'94,fahr,celsius );\^

我直接从C 编程语言"中提取了代码.为什么它不起作用?另外,我使用文本编辑器创建了文本文件.但是,每当我对其进行更改并保存时,它都会恢复为 .rtf.我该如何解决?

解决方案

您将此保存为 RTF 文件.编译器的输入文件必须是纯文本.如果您使用的是 OS X TextEdit.app 程序,请使用 Format 菜单 Make Plain Text 操作将其转换为纯文本,然后重新保存.>

此外(如其他答案所述),您需要用直双引号字符(<代码>").

#include <stdio.h>

main()
{
    float fahr, celsius;
    int lower, upper, step;

    lower = 0;
    upper = 300;
    step = 20;

    fahr = lower;

    while (fahr <= upper) {
        celsius =(5.0/9.0)*(fahr-32.0);
        printf( "%3.0f %6.1f\n",fahr,celsius );
        fahr = fahr + step;
    }
}

I am using a mac. In terminal, I compile with gcc -g file.c and get the following errors and warnings:

file.c:1:1: error: expected identifier or '('
{\rtf1\ansi\ansicpg1252\cocoartf1265\cocoasubrtf190
^
file.c:21:11: warning: missing terminating ' character [-Winvalid-pp-token]
        printf( \'93%3.0f %6.1f\\n\'94,fahr,celsius );\
                 ^

I took the code straight out of "The C Programming Language." Why isn't it working? Also, I created the text file using text editor. However, whenever I make changes to it and save it, it reverts back to a .rtf. How do I fix that?

解决方案

You saved this as an RTF file. The input file to the compiler must be plain text. If you're using the OS X TextEdit.app program, use the Format menu Make Plain Text action to convert it to plain text, then re-save it.

In addition (as mentioned by the other answers), you need to replace the special typographical quote characters (" and ") with straight double-quote characters (").

这篇关于“{\rtf1\ansi"错误编译C程序时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆