Visual Studio的前preSS抱怨缺少“;”在C程序类型后, [英] visual studio express complains missing ';' after type in c program

查看:122
本文介绍了Visual Studio的前preSS抱怨缺少“;”在C程序类型后,的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是我的code中的问题?

 #包括LT&;&stdio.h中GT;
#包括LT&;&string.h中GT;诠释主(){
    FILE *文件;    字符字符串[32] =阿泰斯特去solução    文件= FOPEN(C:\\ file.txt的,W);    的printf(Digite UM texto对gravar没有arquivo:);
    的for(int i = 0; I< 32;我++){
        putc将(串[I]中,文件);
    }    FCLOSE(文件);    返回0;
}

错误:

  C:\\用户\\吉尔赫尔梅\\文档\\ Visual Studio 2010的\\项目\\ HelloWorld的\\ HelloWorld的\\ hello.c的(13):错误C2143:语法错误:缺少;前型
1> C:\\用户\\吉尔赫尔梅\\文档\\ Visual Studio 2010的\\项目\\ HelloWorld的\\ HelloWorld的\\ hello.c的(13):错误C2143:语法错误:缺少;前型
1> C:\\用户\\吉尔赫尔梅\\文档\\ Visual Studio 2010的\\项目\\ HelloWorld的\\ HelloWorld的\\ hello.c的(13):错误C2143:语法错误:在类型失踪)
1> C:\\用户\\吉尔赫尔梅\\文档\\ Visual Studio 2010的\\项目\\ HelloWorld的\\ HelloWorld的\\ hello.c的(13):错误C2143:语法错误:缺少;前型
1> C:\\用户\\吉尔赫尔梅\\文档\\ Visual Studio 2010的\\项目\\ HelloWorld的\\ HelloWorld的\\ hello.c的(13):错误C2065:'我':未声明的标识符
1> C:\\用户\\吉尔赫尔梅\\文档\\ Visual Studio 2010的\\项目\\ HelloWorld的\\ HelloWorld的\\ hello.c的(13):警告C4552:'<' :经营者有没有影响;预计运营商的副作用
1> C:\\用户\\吉尔赫尔梅\\文档\\ Visual Studio 2010的\\项目\\ HelloWorld的\\ HelloWorld的\\ hello.c的(13):错误C2065:'我':未声明的标识符
1> C:\\用户\\吉尔赫尔梅\\文档\\ Visual Studio 2010的\\项目\\ HelloWorld的\\ HelloWorld的\\ hello.c的(13):错误C2059:语法错误:')'
1> C:\\用户\\吉尔赫尔梅\\文档\\ Visual Studio 2010的\\项目\\ HelloWorld的\\ HelloWorld的\\ hello.c的(13):错误C2143:语法错误:缺少;前{
1> C:\\用户\\吉尔赫尔梅\\文档\\ Visual Studio 2010的\\项目\\ HelloWorld的\\ HelloWorld的\\ hello.c的(14):错误C2065:'我':未声明的标识符
==========所有重建:0成功,1失败,0已跳过==========


解决方案

显然你这个编译为C,而不是C ++。 VS不支持C99,在这种情况下,你可能无法做到这一点:

 的for(int i = 0; I< 32;我++)

您需要这样做,而不是:

  INT I;...对于(i = 0; I< 32;我++)

在哪里的声明 I 必须走在了所有功能的语句之前。

What is the problem with my code?

#include<stdio.h>
#include<string.h>

int main() {
    FILE *file;

    char string[32] = "Teste de solução";

    file = fopen("C:\file.txt", "w");

    printf("Digite um texto para gravar no arquivo: ");
    for(int i = 0; i < 32; i++) {
        putc(string[i], file);
    }

    fclose(file);

    return 0;
}

Error:

c:\users\guilherme\documents\visual studio 2010\projects\helloworld\helloworld\hello.c(13): error C2143: syntax error : missing ';' before 'type'
1>c:\users\guilherme\documents\visual studio 2010\projects\helloworld\helloworld\hello.c(13): error C2143: syntax error : missing ';' before 'type'
1>c:\users\guilherme\documents\visual studio 2010\projects\helloworld\helloworld\hello.c(13): error C2143: syntax error : missing ')' before 'type'
1>c:\users\guilherme\documents\visual studio 2010\projects\helloworld\helloworld\hello.c(13): error C2143: syntax error : missing ';' before 'type'
1>c:\users\guilherme\documents\visual studio 2010\projects\helloworld\helloworld\hello.c(13): error C2065: 'i' : undeclared identifier
1>c:\users\guilherme\documents\visual studio 2010\projects\helloworld\helloworld\hello.c(13): warning C4552: '<' : operator has no effect; expected operator with side-effect
1>c:\users\guilherme\documents\visual studio 2010\projects\helloworld\helloworld\hello.c(13): error C2065: 'i' : undeclared identifier
1>c:\users\guilherme\documents\visual studio 2010\projects\helloworld\helloworld\hello.c(13): error C2059: syntax error : ')'
1>c:\users\guilherme\documents\visual studio 2010\projects\helloworld\helloworld\hello.c(13): error C2143: syntax error : missing ';' before '{'
1>c:\users\guilherme\documents\visual studio 2010\projects\helloworld\helloworld\hello.c(14): error C2065: 'i' : undeclared identifier
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========

解决方案

Evidently you are compiling this as C, not C++. VS doesn't support C99, in which case you may not do this:

for (int i = 0; i < 32; i++)

You need to do this instead:

int i;

...

for(i = 0; i < 32; i++)

Where the declaration of i must come before all statements in the function.

这篇关于Visual Studio的前preSS抱怨缺少“;”在C程序类型后,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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