void Input(int arr[100])
{
int index;
printf("Enter the array\n");
for(index = 0; index < 100; index++)
{
printf("Enter %d number\n", index+1);
scanf("%d", &arr[index]);
}
}
int minValue = 32767;
int index;
int sort;
for(a = 0;a < 100;a++)
{
if(arr[a] < minValue)
{
index = a;
}
}
for(a = 0;a < (sizeof(arr)) / 4;a++)
{
index++;
arr1[a] = arr[index];
}
for(a = 0;a < (sizeof(arr1))/4;a++)
{
for(index = a;index < (sizeof(arr1))/4;index++)
{
if(arr1[a] > arr1[index])
{
sort = arr1[a];
arr1[a] = arr1[index];
arr1[index] = sort;
}
}
}
for(a = 0;a < (sizeof(arr1))/4;a++)
{
printf("%d\n", arr1[a]);
}
int main()
{
char choise = '0';
int loaded = 0;
int arr[100];
do
{
printf("---------------MENU----------------\n" );
printf("- 1.Enter array -\n");
printf("- 2.Use already entered array -\n");
printf("- Space for exit program -\n");
printf("-----------------------------------\n" );
scanf("%c", &choise);
if(choise == ' ')
{
printf("Bye Bye\n\n");
return 0;
}
switch(choise)
{
case '1':
Input(arr);
loaded = 1;
break;
case '2':
break;
default:
printf("You have entered an invalid value\n");
break;
}
if(!loaded)
{
printf("You haven't enter an array yet.Please choose 1 first.\n");
}
else
{
magic(arr);
}
} while(choise != ' ');
return 0;
}
你好这是我的第一个c项目,我有一些语法错误我叮叮当然,它不能被编译?请向我解释我的恐怖分子在哪里?
我使用Visual Studio 2010编写代码。
我使用的指令也是:
#include <stdio.h>
#include <conio.h>
#include <string.h>
#include <stdlib.h>
这是编译器的错误:
1>------ Build started: Project: Georgi, Configuration: Debug Win32 ------
1> Georgi.cpp
1>c:\users\alexievpc\documents\visual studio 2010\projects\georgi\georgi\georgi.cpp(14): warning C4996: 'scanf': This function or variable may be unsafe. Consider using scanf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\stdio.h(304) : see declaration of 'scanf'
1>c:\users\alexievpc\documents\visual studio 2010\projects\georgi\georgi\georgi.cpp(20): error C2059: syntax error : 'for'
1>c:\users\alexievpc\documents\visual studio 2010\projects\georgi\georgi\georgi.cpp(20): error C2143: syntax error : missing ')' before ';'
1>c:\users\alexievpc\documents\visual studio 2010\projects\georgi\georgi\georgi.cpp(20): error C2143: syntax error : missing ';' before '<'
1>c:\users\alexievpc\documents\visual studio 2010\projects\georgi\georgi\georgi.cpp(20): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\alexievpc\documents\visual studio 2010\projects\georgi\georgi\georgi.cpp(20): error C2143: syntax error : missing ';' before '++'
1>c:\users\alexievpc\documents\visual studio 2010\projects\georgi\georgi\georgi.cpp(20): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\alexievpc\documents\visual studio 2010\projects\georgi\georgi\georgi.cpp(20): error C2086: 'int a' : redefinition
1> c:\users\alexievpc\documents\visual studio 2010\projects\georgi\georgi\georgi.cpp(20) : see declaration of 'a'
1>c:\users\alexievpc\documents\visual studio 2010\projects\georgi\georgi\georgi.cpp(20): error C2059: syntax error : ')'
1>c:\users\alexievpc\documents\visual studio 2010\projects\georgi\georgi\georgi.cpp(21): error C2143: syntax error : missing ';' before '{'
1>c:\users\alexievpc\documents\visual studio 2010\projects\georgi\georgi\georgi.cpp(21): error C2447: '{' : missing function header (old-style formal list?)
1>c:\users\alexievpc\documents\visual studio 2010\projects\georgi\georgi\georgi.cpp(27): error C2059: syntax error : 'for'
1>c:\users\alexievpc\documents\visual studio 2010\projects\georgi\georgi\georgi.cpp(27): error C2143: syntax error : missing ')' before ';'
1>c:\users\alexievpc\documents\visual studio 2010\projects\georgi\georgi\georgi.cpp(27): error C2143: syntax error : missing ';' before '<'
1>c:\users\alexievpc\documents\visual studio 2010\projects\georgi\georgi\georgi.cpp(27): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\alexievpc\documents\visual studio 2010\projects\georgi\georgi\georgi.cpp(27): error C2086: 'int a' : redefinition
1> c:\users\alexievpc\documents\visual studio 2010\projects\georgi\georgi\georgi.cpp(20) : see declaration of 'a'
1>c:\users\alexievpc\documents\visual studio 2010\projects\georgi\georgi\georgi.cpp(27): error C2143: syntax error : missing ';' before '++'
1>c:\users\alexievpc\documents\visual studio 2010\projects\georgi\georgi\georgi.cpp(27): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\alexievpc\documents\visual studio 2010\projects\georgi\georgi\georgi.cpp(27): error C2086: 'int a' : redefinition
1> c:\users\alexievpc\documents\visual studio 2010\projects\georgi\georgi\georgi.cpp(20) : see declaration of 'a'
1>c:\users\alexievpc\documents\visual studio 2010\projects\georgi\georgi\georgi.cpp(27): error C2059: syntax error : ')'
1>c:\users\alexievpc\documents\visual studio 2010\projects\georgi\georgi\georgi.cpp(28): error C2143: syntax error : missing ';' before '{'
1>c:\users\alexievpc\documents\visual studio 2010\projects\georgi\georgi\georgi.cpp(28): error C2447: '{' : missing function header (old-style formal list?)
1>c:\users\alexievpc\documents\visual studio 2010\projects\georgi\georgi\georgi.cpp(32): error C2059: syntax error : 'for'
1>c:\users\alexievpc\documents\visual studio 2010\projects\georgi\georgi\georgi.cpp(32): error C2143: syntax error : missing ')' before ';'
1>c:\users\alexievpc\documents\visual studio 2010\projects\georgi\georgi\georgi.cpp(32): error C2143: syntax error : missing ';' before '<'
1>c:\users\alexievpc\documents\visual studio 2010\projects\georgi\georgi\georgi.cpp(32): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\alexievpc\documents\visual studio 2010\projects\georgi\georgi\georgi.cpp(32): error C2086: 'int a' : redefinition
1> c:\users\alexievpc\documents\visual studio 2010\projects\georgi\georgi\georgi.cpp(20) : see declaration of 'a'
1>c:\users\alexievpc\documents\visual studio 2010\projects\georgi\georgi\georgi.cpp(32): error C2143: syntax error : missing ';' before '++'
1>c:\users\alexievpc\documents\visual studio 2010\projects\georgi\georgi\georgi.cpp(32): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\alexievpc\documents\visual studio 2010\projects\georgi\georgi\georgi.cpp(32): error C2086: 'int a' : redefinition
1> c:\users\alexievpc\documents\visual studio 2010\projects\georgi\georgi\georgi.cpp(20) : see declaration of 'a'
1>c:\users\alexievpc\documents\visual studio 2010\projects\georgi\georgi\georgi.cpp(32): error C2059: syntax error : ')'
1>c:\users\alexievpc\documents\visual studio 2010\projects\georgi\georgi\georgi.cpp(33): error C2143: syntax error : missing ';' before '{'
1>c:\users\alexievpc\documents\visual studio 2010\projects\georgi\georgi\georgi.cpp(33): error C2447: '{' : missing function header (old-style formal list?)
1>c:\users\alexievpc\documents\visual studio 2010\projects\georgi\georgi\georgi.cpp(44): error C2059: syntax error : 'for'
1>c:\users\alexievpc\documents\visual studio 2010\projects\georgi\georgi\georgi.cpp(44): error C2143: syntax error : missing ')' before ';'
1>c:\users\alexievpc\documents\visual studio 2010\projects\georgi\georgi\georgi.cpp(44): error C2143: syntax error : missing ';' before '<'
1>c:\users\alexievpc\documents\visual studio 2010\projects\georgi\georgi\georgi.cpp(44): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\alexievpc\documents\visual studio 2010\projects\georgi\georgi\georgi.cpp(44): error C2086: 'int a' : redefinition
1> c:\users\alexievpc\documents\visual studio 2010\projects\georgi\georgi\georgi.cpp(20) : see declaration of 'a'
1>c:\users\alexievpc\documents\visual studio 2010\projects\georgi\georgi\georgi.cpp(44): error C2143: syntax error : missing ';' before '++'
1>c:\users\alexievpc\documents\visual studio 2010\projects\georgi\georgi\georgi.cpp(44): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\alexievpc\documents\visual studio 2010\projects\georgi\georgi\georgi.cpp(44): error C2086: 'int a' : redefinition
1> c:\users\alexievpc\documents\visual studio 2010\projects\georgi\georgi\georgi.cpp(20) : see declaration of 'a'
1>c:\users\alexievpc\documents\visual studio 2010\projects\georgi\georgi\georgi.cpp(44): error C2059: syntax error : ')'
1>c:\users\alexievpc\documents\visual studio 2010\projects\georgi\georgi\georgi.cpp(45): error C2143: syntax error : missing ';' before '{'
1>c:\users\alexievpc\documents\visual studio 2010\projects\georgi\georgi\georgi.cpp(45): error C2447: '{' : missing function header (old-style formal list?)
1>c:\users\alexievpc\documents\visual studio 2010\projects\georgi\georgi\georgi.cpp(84): error C3861: 'magic': identifier not found
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
答案 0 :(得分:2)
您正在使用函数外的语句(for(a = 0;a < 100;a++)
最多int main()
)。这不合法C.
编译器不知道函数magic
- 包括正确的头文件或将其声明/定义添加到编译源。
另请注意,您的代码既没有声明a
也没有声明arr1
,后者可能也需要内存分配(虽然查看编译器消息,但声明并不包含在内。您发布的代码片段)。