我不确定下一步该做什么,因为这些错误对我来说没有任何意义,也许我做错了别人可以看到的事情。这具有所有正确的结构,只是我的语法错误。任何帮助表示赞赏。
这是我的代码,这是我已经走了多远,当我尝试编译时,我得到了这些错误:
gcc Pointers.c
Pointers.c:14: error: expected ‘)’ before ‘array’
Pointers.c:32: error: expected ‘)’ before ‘array’
Pointers.c:44: error: expected ‘)’ before ‘array’
Pointers.c:56: error: expected ‘)’ before ‘array’
Pointers.c:78: error: expected ‘)’ before ‘pointer’
Pointers.c: In function ‘main’:
Pointers.c:102: error: ‘array’ undeclared (first use in this function)
Pointers.c:102: error: (Each undeclared identifier is reported only once
Pointers.c:102: error: for each function it appears in.)
Pointers.c:104: error: ‘pointer’ undeclared (first use in this function)
这是作业页面:
http://www.cs.miami.edu/~wuchtys/CSC322-13F/Assessment/LT5.html
#include <stdio.h>
#include <stdlib.h>
#define SIZE_OF_ARRAY 5
//=============================================================================
int *IntegerPtr;
int ArrayInt[SIZE_OF_ARRAY];
int *ArrayPtr[SIZE_OF_ARRAY];
//-----------------------------------------------------------------------------
/* Initializes the elements of an array of five integers to random integers
Initializes the elements of an array of five pointers to integers to point to the corresponding elements of the array of integers. */
void ArrayInitialize(ArrayInt array,ArrayPtr pointer){
int i;
srand(getpid());
for (i =0, int < SIZE_OF_ARRAY; i++){
array[i] = (int)rand()
for (i =0, int < SIZE_OF_ARRAY; i++){
pointer[i] = &array[i];
}
}
}
//-----------------------------------------------------------------------------
/*Have a function that prints an array of five integers*/
void ArrayPrint(ArrayInt array){
int i;
for (i =0, int < SIZE_OF_ARRAY; i++){
printf("%d : %10d \n",i,array[i]);
}
printf("\n");
}
//-----------------------------------------------------------------------------
/*Have a function that prints the integers pointed to by an array of five pointers to integers.*/
void ArrayPointerPrint(ArrayInt array){
int i;
for (i =0, int < SIZE_OF_ARRAY; i++){
printf("%d : %10d \n",i,pointer[i]);
}
printf("\n");
}
//-----------------------------------------------------------------------------
/*Have a function that uses a bubble-sort to sort an array of five integers, in ascending order of the integers. */
void ArrayBubbleSort(ArrayInt array){
int i;
int j;
int temp;
for( i = (SIZE_OF_ARRAY - 1); i >= 0; i-- )
{
for( j = 1; j <= i; j++ )
{
if( *(array+(j-1)) > *(array+j))
{
temp = *array+(j-1));
*array+(j-1)) = array+(j));
*array+(j) = temp;
}
}
}
}
//-----------------------------------------------------------------------------
/*Have a function that uses a bubble-sort to sort an array of five pointers to integers */
void PointerBubbleSort(ArrayPtr pointer){
int i;
int j;
int temp;
for( i = (SIZE_OF_ARRAY - 1); i >= 0; i-- )
{
for( j = 1; j <= i; j++ )
{
if( *(pointer+(j-1)) > *(pointer+j))
{
temp = *pointer+(j-1));
*pointer+(j-1)) = pointer+(j));
*pointer+(j) = temp;
}
}
}
}
//-----------------------------------------------------------------------------
int main(void) {
array[SIZE_OF_ARRAY];
pointer[SIZE_OF_ARRAY];
ArrayInitialize(array,pointer);
ArrayPrint(array);
PointerBubbleSort(pointer);
ArrayPointerPrint(pointer);
ArrayBubbleSort(array);
ArrayPrint(array);
ArrayPointerPrint(pointer);
return(EXIT_SUCCESS);
}
答案 0 :(得分:0)
这些是变量:
int *IntegerPtr;
int ArrayInt[SIZE_OF_ARRAY];
int *ArrayPtr[SIZE_OF_ARRAY];
您的代码正在使用它们,如typedef。
也许不是这个
void ArrayInitialize(ArrayInt array,ArrayPtr pointer){
您想要使用
void ArrayInitialize(int *array,int *pointer){
在您的所有代码中,尝试用ArrayInt
替换ArrayPointer
和int *
,我认为它会
编译。
然后改变
array[SIZE_OF_ARRAY];
pointer[SIZE_OF_ARRAY];
到
int array[SIZE_OF_ARRAY];
int pointer[SIZE_OF_ARRAY];