基本上,我一直在C编程上做类,在那个类中我们使用Linux机器来编写和编译我们的代码。在Windows 7上从linux到visual studio 2010的c编程问题
下面的程序是我们第一个任务的一部分,我在课堂上编译并在Linux上运行它,但没有问题,但已将它带回家我不能在我的生活中让它在Visual Studio 2010中编译最终的,或者带有MinGW编译器的eclipse IDE。
在导致我的代码失败的两个操作系统之间切换是否存在一些典型问题?或者让我作为新手,写了一些不符合VS 2010或Eclipse的丑陋代码?
尝试修复我从VS 2010中得到的错误消息似乎是徒劳的,所以我倾向于从我的计算机中丢失重要的东西。我也设置VS 2010编译C代码,所以我不认为这是问题。从VS2010
错误:
project1a.c(38):错误C2143:语法错误:缺少 ';'前 '类型'
project1a.c(41):错误C2065:I':未声明的标识符
project1a.c(44):错误C2065:userArray':未声明的标识符
project1a.c(44):错误C2065:I':未声明的标识符
project1a.c(44):错误C2109:下标要求数组或指针类型
project1a.c(51):错误C2065:userArray':未声明的标识符
有是'i'的多个实例:这些错误之间的未声明的标识符错误
#include <stdio.h>
#include <stdlib.h>
int n;
float total, avg;
int sumavg(void);
int main(void)
{
//First time scan for the value to be assigned to n.
printf("Hey, Enter a number or 999 to exit:> ");
scanf("%d", &n);
//if n == 999 then exit the program
while(n != 999)
{
//enter the sumavg function.
sumavg();
//Try to run the program again.
printf("Hey, Enter a number or 999 to exit:> ");
scanf("%d", &n);
}
//exit program.
return EXIT_SUCCESS;
}
int sumavg(void)
{
//Define a number that will be used for the array size.
printf("Hey, now enter %d more numbers:>\n", n);
//Define the size of array using the number assigned to the variable "n".
int userArray[n], i;
//Construct the array, one position at a time using the for loop.
for (i = 0; i < n; i++)
{
//Assign a value to userArray[i] while i < n(the size of the array).
scanf("%d", &userArray[i]);
}
//Calculate the sum by looping through each position in the userArray[i].
for (i = 0; i < n; i++)
{
//Take the current position in the array and add it to the variable: "total"
total += userArray[i];
}
//Calculate the average
avg = total/n;
//Print the sum followed by the average
printf("Sum is: %.1lf\n", total);
printf("The average is: %.1lf\n", avg);
//reset total and avg in case future iterations are performed.
total = 0;
avg = 0;
}
您得到的错误是什么? – 2012-03-20 03:27:57
请发布一些编译器警告/错误。 – Mosby 2012-03-20 03:28:40
您可以发布您在编译器中获得的错误消息吗?这将有助于缩小问题的范围。 – Gangadhar 2012-03-20 03:29:03