![]() |
| | #1 |
| Registered User Join Date: Jun 2009
Posts: 28
| Help with error Code: sort.c:21error: expected â=â, â,â, â;â, âasmâ or â__attribute__â before âintâ
sort.c:46: error: expected â=â, â,â, â;â, âasmâ or â__attribute__â before â{â to ken
Code: #include <stdio.h>
#include <stdlib.h>
#include <string.h>
void quick_sort(int **a, int left, int right)
void swap(int **a, int i, int j)
int main (){
int number = 0;
printf("How many entries in the sort array?\n");
scanf( "%d", &number);
int *a = malloc(sizeof(int)*number);
int j = 0;
for( j = 0; j<number; j++){
a[j] = random()%100;
printf("%d\n", a[j]);
}
quick_sort(a, 0, number);
int d;
for(d=0; d<number;d++){
printf("%d\n", a[d]);
}
return 0;
}
void swap(int **a, int i, int j){
int temp;
temp = a[i];
a[j] = a[i];
a[j] = temp;
}
void insertion_sort(int **a, int n) {
int k;
for (k = 1; k < n; ++k) {
int key = a[k];
int i = k - 1;
while ((i >= 0) && (key < a[i])) {
a[i + 1] = a[i];
--i;
}
a[i + 1] = key;
}
}
|
| bigparker is offline | |
| | #2 |
| Registered User Join Date: Sep 2004 Location: California
Posts: 2,845
| Code: void quick_sort(int **a, int left, int right) void swap(int **a, int i, int j) EDIT: Also, why do those methods take a double pointer? It seems like you just need to pass the pointer here. Last edited by bithub; 07-16-2009 at 03:51 PM. |
| bithub is offline | |
| | #3 |
| and the Hat of Guessing Join Date: Nov 2007
Posts: 8,740
| Which line is line 21 and which line is line 46? By my count, line 21 is "a[j] = random()%100;", which doesn't have an int token on it. |
| tabstop is offline | |
| | #4 |
| Registered User Join Date: Jun 2009
Posts: 28
| Code: line 21 is at "int main(){}"
line 46 is "void swap(int *, int, int)"
|
| bigparker is offline | |
| | #5 | |
| Registered User Join Date: Sep 2004 Location: California
Posts: 2,845
| Quote:
| |
| bithub is offline | |
| | #6 |
| and the Hat of Guessing Join Date: Nov 2007
Posts: 8,740
| So yes your prototypes need semicolons. And you only need to pass a pointer to your dynamic array if you intend to completely blow your dynamic array away and create a new one. (I.e., you need your pointer to point somewhere else.) If you're just going to move things around in the array you already have, then there's no need for an extra star. (Your dynamic array is an int *, so the ints that are pointed to can be changed by a function, but not the value of the pointer itself.) |
| tabstop is offline | |
| | #7 | ||
| Registered User Join Date: Jun 2009
Posts: 28
| Quote:
Quote:
| ||
| bigparker is offline | |
![]() |
| Tags |
| dynamic array, error |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Getting an error with OpenGL: collect2: ld returned 1 exit status | Lorgon Jortle | C++ Programming | 6 | 05-08-2009 08:18 PM |
| An error is driving me nuts! | ulillillia | C Programming | 5 | 04-04-2009 09:15 PM |
| Making C DLL using MSVC++ 2005 | chico1st | C Programming | 26 | 05-28-2008 01:17 PM |
| Connecting to a mysql server and querying problem | Diod | C++ Programming | 8 | 02-13-2006 10:33 AM |
| Couple C questions :) | Divx | C Programming | 5 | 01-28-2003 01:10 AM |