error in bubble sort

i have some error but i can't find it. please help!

Sorting.c: In function ‘bubble’:
Sorting.c:5: error: stray ‘\302’ in program
Sorting.c:5: error: stray ‘\240’ in program
Sorting.c:5: error: stray ‘\302’ in program
Sorting.c:5: error: stray ‘\240’ in program
Sorting.c:5: error: stray ‘\302’ in program
Sorting.c:5: error: stray ‘\240’ in program
Sorting.c:5: error: stray ‘\302’ in program
Sorting.c:5: error: stray ‘\240’ in program
Sorting.c:6: error: stray ‘\302’ in program
Sorting.c:6: error: stray ‘\240’ in program
Sorting.c:6: error: stray ‘\302’ in program
Sorting.c:6: error: stray ‘\240’ in program
Sorting.c:6: error: stray ‘\302’ in program
Sorting.c:6: error: stray ‘\240’ in program
Sorting.c:6: error: stray ‘\302’ in program
Sorting.c:6: error: stray ‘\240’ in program
Sorting.c:7: error: stray ‘\302’ in program
Sorting.c:7: error: stray ‘\240’ in program
Sorting.c:7: error: stray ‘\302’ in program
Sorting.c:7: error: stray ‘\240’ in program
Sorting.c:7: error: stray ‘\302’ in program
Sorting.c:7: error: stray ‘\240’ in program
Sorting.c:7: error: stray ‘\302’ in program
Sorting.c:7: error: stray ‘\240’ in program
Sorting.c:7: error: stray ‘\302’ in program
Sorting.c:7: error: stray ‘\240’ in program
Sorting.c:7: error: stray ‘\302’ in program
Sorting.c:7: error: stray ‘\240’ in program
Sorting.c:8: error: stray ‘\302’ in program
Sorting.c:8: error: stray ‘\240’ in program
Sorting.c:8: error: stray ‘\302’ in program
Sorting.c:8: error: stray ‘\240’ in program
Sorting.c:8: error: stray ‘\302’ in program
Sorting.c:8: error: stray ‘\240’ in program
Sorting.c:8: error: stray ‘\302’ in program
Sorting.c:8: error: stray ‘\240’ in program
Sorting.c:8: error: stray ‘\302’ in program
Sorting.c:8: error: stray ‘\240’ in program
Sorting.c:8: error: stray ‘\302’ in program
Sorting.c:8: error: stray ‘\240’ in program
Sorting.c:9: error: stray ‘\302’ in program
Sorting.c:9: error: stray ‘\240’ in program
Sorting.c:9: error: stray ‘\302’ in program
Sorting.c:9: error: stray ‘\240’ in program
Sorting.c:9: error: stray ‘\302’ in program
Sorting.c:9: error: stray ‘\240’ in program
Sorting.c:9: error: stray ‘\302’ in program
Sorting.c:9: error: stray ‘\240’ in program
Sorting.c:9: error: stray ‘\302’ in program
Sorting.c:9: error: stray ‘\240’ in program
Sorting.c:9: error: stray ‘\302’ in program
Sorting.c:9: error: stray ‘\240’ in program
Sorting.c:10: error: stray ‘\302’ in program
Sorting.c:10: error: stray ‘\240’ in program
Sorting.c:10: error: stray ‘\302’ in program
Sorting.c:10: error: stray ‘\240’ in program
Sorting.c:10: error: stray ‘\302’ in program
Sorting.c:10: error: stray ‘\240’ in program
Sorting.c:10: error: stray ‘\302’ in program
Sorting.c:10: error: stray ‘\240’ in program
Sorting.c:10: error: stray ‘\302’ in program
Sorting.c:10: error: stray ‘\240’ in program
Sorting.c:10: error: stray ‘\302’ in program
Sorting.c:10: error: stray ‘\240’ in program
Sorting.c:11: error: stray ‘\302’ in program
Sorting.c:11: error: stray ‘\240’ in program
Sorting.c:11: error: stray ‘\302’ in program
Sorting.c:11: error: stray ‘\240’ in program
Sorting.c:11: error: stray ‘\302’ in program
Sorting.c:11: error: stray ‘\240’ in program
Sorting.c:11: error: stray ‘\302’ in program
Sorting.c:11: error: stray ‘\240’ in program
Sorting.c:11: error: stray ‘\302’ in program
Sorting.c:11: error: stray ‘\240’ in program
Sorting.c:12: error: stray ‘\302’ in program
Sorting.c:12: error: stray ‘\240’ in program
Sorting.c:12: error: stray ‘\302’ in program
Sorting.c:12: error: stray ‘\240’ in program
Sorting.c:12: error: stray ‘\302’ in program
Sorting.c:12: error: stray ‘\240’ in program

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <stdio.h>
void bubble(int *data, int count){
	int i, last;
	for (last = count-1; last > 0; last--){
	    for (i = 0; i < last; i++)
	    if (data[i+1] < data[i]){
	      // Swap adjacent elements 
	      int t = data[i+1];
	      data[i+1] = data[i];
	      data[i] = t;
     }
   }
}

int main(void){
	int needToBeSorted[] = {456,2,457,34,1,9,36,97,344,38,23,76,54,62,6};
	int count =15;
	int *p;
	p=&needToBeSorted;
	bubble(int p,int count);
	return 1;
}.
Last edited on
Click the little gear on the upper right corner of your code snippet. You'll see that somehow you've gotten some extra invisible characters in your source code.

Some other problems:
Not an error as far as the compiler is concerned, but your bracing and indentation in your bubble function make it difficult to read. Even though the for loop starting on line 5 contains a single if statement (thus will work as intended), I think you should still wrap the body of the for loop in braces. Then, line the braces up with the scope that they envelop.

On line 20, you shouldn't put the parameter types in the function call. Remove both "int"s.

Line 18 and 19 are unnecessary. You can invoke bubble like this:
bubble(needToBeSorted, count);
Last edited on
Id be happy to help if you explain what the program needs to do such as do you want the numbers least to greatest or the oppisite?
Remove the address-of operator as well on line 19, the pointer will point to the first element in the array.
Topic archived. No new replies allowed.