0

我的教授给了我们一些代码,并说它应该能够编译,但是我遇到了各种各样的错误,我不知道出了什么问题,因为我对 c 没有任何经验。它是一个汇编语言类,我们应该编写汇编代码来匹配 c 代码正在做的事情。他告诉我们用c运行程序来感受一下。

#include <stdio.h>
#define  SIZE  40

main()
{
int v[SIZE];
register int gap, i, j, temp;

/*  Initialize array to random positive integers mod 256  */
for (i = 0; i < SIZE; i++)
    v[i] = rand() & 0xFF;

/*  Display the unsorted array  */
for (i = 0; i < SIZE; i++)
    printf(“v[%-d] = %-d\n”, i, v[i]);

/*  Sort the array using a shell sort  */
for (gap = SIZE / 2; gap > 0; gap /= 2) {
    for (i = gap; i < SIZE; i++) {
        for (j = i - gap; j >= 0 && v[j] > v[j + gap]; j -= gap) {
            /*  Exchange out of order items  */
            temp = v[j];
            v[j] = v[j + gap];
            v[j + gap] = temp;
        }
    }
}

/*  Display the sorted array  */
for (i = 0; i < SIZE; i++)
    printf(“v[%-d] = %-d\n”, i, v[i]);
}

我得到的错误是第 15 行和第 31 行中的错误,所以每一行都有一个 printf。

As3.c: In function ’main’:
As3.c:15: error: stray ’\223’ in program
As3.c:15: error: expected expression before ’%’ token 
As3.c:15: error: expected expression before ’%’ token
As3.c:15: error: stray ’\’ in program
As3.c:15: error: stray ’\224’ in program
As3.c:31:error: stray ’\223’ in program
As3.c:31:error: expected expression before ’%’ token
As3.c:31:error: expected expression before ’%’ token
As3.c:31:error: stray ’\’ in program
As3.c:31:error: stray ’\224’ in program

任何帮助都会得到帮助,我相信它一定很简单,但我是 c 的菜鸟。

4

1 回答 1

9
于 2012-10-25T04:13:58.597 回答