我不确定下一步该做什么,因为这些错误对我来说没有任何意义,也许我做错了什么,别人可以看到。这有所有正确的结构,只是我有错误的语法。任何帮助都是非常感谢的。
这是我的代码,这是我得到的结果,当我尝试编译时,我得到了这些错误:
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);
}
发布于 2013-10-06 11:14:28
以下是变量:
int *IntegerPtr;
int ArrayInt[SIZE_OF_ARRAY];
int *ArrayPtr[SIZE_OF_ARRAY];
您的代码就像使用typedefs一样使用它们。
也许不是这样
void ArrayInitialize(ArrayInt array,ArrayPtr pointer){
您想要使用
void ArrayInitialize(int *array,int *pointer){
在您的所有代码中,尝试用int *
替换ArrayInt
和ArrayPointer
,我认为它会被编译。
然后改变
array[SIZE_OF_ARRAY];
pointer[SIZE_OF_ARRAY];
至
int array[SIZE_OF_ARRAY];
int pointer[SIZE_OF_ARRAY];
https://stackoverflow.com/questions/19205018
复制相似问题