기본적으로 C 프로그래밍에 관한 수업을 들었습니다.이 수업에서는 리눅스 컴퓨터를 사용하여 코드를 작성하고 컴파일합니다.c 프로그래밍 문제 리눅스에서 Visual Studio 2010을 윈도우 7로 옮기기
아래의 프로그램은 첫 번째 과제의 일부로, 문제가없는 수업 중에 그것을 컴파일하여 실행했지만 집에 가져 가서 데려왔다. 비주얼 스튜디오 2010에서 컴파일 할 수 없다. 궁극적 인, 또는 MinGW 컴파일러와 일식 IDE.
내 코드가 작동하지 않는 두 운영 체제를 전환 할 때 몇 가지 일반적인 문제가 있습니까? 또는 나는 신인이 되려면 VS 2010 또는 Eclipse와 동의하지 않는 추악한 코드를 작성해야합니까?
VS 2010에서 가져온 오류 메시지를 수정하려는 시도는 쓸모없는 것처럼 보이므로 내 컴퓨터에서 빠져 나오는 것이 중요합니다. 나는 VS 2010을 C 코드를 컴파일하도록 설정 했으므로 문제는 아니라고 생각합니다. VS2010에서
오류 :
project1a.c (38) : 오류 C2143 : 구문 오류 : 누락 ';' 오류 C2065 : 'I': 선언되지 않은 식별자
project1a.c (44) : 오류 C2065 'userArray'선언되지 않은 식별자
project1a.c (44) '타입'
project1a.c (41) 전에 오류 C2065 'I': 선언되지 않은 식별자
project1a.c (44) : 오류 C2109 : 오류 C2065 : 첨자는 배열 또는 포인터 형
project1a.c (51)가 필요 '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;
}
으로 변경해야할까요? –
일부 컴파일러 경고/오류를 게시하십시오. – Mosby
두 컴파일러에서 모두 가져 오는 오류 메시지를 게시 할 수 있습니까? 그것은 문제를 좁히는 데 도움이 될 것입니다. – Gangadhar