My professor gave us some code in a Microsoft Word document and said it should be able to compile, but I'm getting all sorts of errors and I don't know whats wrong because I have no experience whatsoever with C.
It's an assembly language class and we're supposed to write assembly code to match what the C code is doing. He told us to run the program in C to get a feel of things.
#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]);
}
The errors I get are strays in lines 15 and 31, so each line that has a printf in it.
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
How can I fix this problem?