program in C, shell sort.
i've got this error : sort.c(13) : error C2371: 'shellSort' : redefinition; different basic types -
#include <stdio.h>
-
-
int a[6] = {5, 9 , 2, 8, 7, 1};
-
int main(){
-
int m;
-
m = 0;
-
shellSort(a, 6);
-
for(m = 0; m<20; m++)
-
printf("\n%d", a[m]);
-
-
return 0;
-
}
-
void shellSort( int a[],int N){
-
int i, j, inc;
-
int tmp;
-
for(inc = N/2; inc>0; inc /= 2)
-
for(i = inc; i < N; i ++)
-
{
-
tmp = a[i];
-
for(j = i; j>= inc; j -= inc)
-
if(tmp <a[j-inc])
-
a[j] = a[j - inc];
-
else
-
break;
-
a[j] = tmp;
-
}
-
-
}
-
Is that the only message you get nothing on line 7?
You called shellSort at line 7, it wasn't prototyped so the C compiler automatically assigned as a prototype returning int it declared it as
int shellSort();
Then at line 15 you define it as
void shellSort( int a[],int N)
And you get an error because you have defined it as returning void but the compiler declared it as returning int.
Predeclare you function at line 2 to avoid this.
2 2964 Banfa 9,065
Expert Mod 8TB
Is that the only message you get nothing on line 7?
You called shellSort at line 7, it wasn't prototyped so the C compiler automatically assigned as a prototype returning int it declared it as
int shellSort();
Then at line 15 you define it as
void shellSort( int a[],int N)
And you get an error because you have defined it as returning void but the compiler declared it as returning int.
Predeclare you function at line 2 to avoid this.
Thanks, I need to study so much. I didn't know that.
this is fixed up code -
#include <stdio.h>
-
-
int a[6] = {5, 9 , 2, 8, 7, 1};
-
int main(){
-
int m;
-
m = 0;
-
printf("Unsorted list:");
-
for(m = 0; m<6; m++)
-
printf("\n%d", a[m]);
-
shellSort(a, 6);
-
printf("\nShell Sorted: ");
-
for(m = 0; m<6; m++)
-
printf("\n%d", a[m]);
-
-
return 0;
-
}
-
int shellSort( int a[],int N){
-
int i, j, inc;
-
int tmp;
-
for(inc = N/2; inc>0; inc /= 2)
-
for(i = inc; i < N; i ++)
-
{
-
tmp = a[i];
-
for(j = i; j>= inc; j -= inc)
-
if(tmp <a[j-inc])
-
a[j] = a[j - inc];
-
else
-
break;
-
a[j] = tmp;
-
}
-
return 0;
-
}
-
Sign in to post your reply or Sign up for a free account.
Similar topics
by: John |
last post by:
I currently have a list box that contains regions in the US
(Northeast, Midwest, South, etc.). I am retrieving this data from my
Region table(see below). Users have the ability to select a region...
|
by: Ben Jacobs-Swearingen |
last post by:
Hello,
I just started learning C a couple weeks ago from Kernighan and
Ritchie (first edition -- I can't afford the newer second edition), and
have really enjoyed it so far. But I am having...
|
by: Schnogge |
last post by:
Hi!
it is possible to generate an multiple-dimensional array
with different data types? Or is it possible to combine
a one-dimensional array with an other which has an other
data type?
How...
|
by: aprivate |
last post by:
Hi
I tried all the examples in the visual studio IDE but
the array.sort (array,icomparer) examples fails to
work in VB.NET for Smart Devices..
its get an error before it is compiled...
Is...
|
by: Shawn |
last post by:
As if it won't be clear enough from my code, I'm pretty new to C
programming. This code is being compiled with an ANSI-C compatible
compiler for a microcontroller. That part, I believe, will be...
|
by: Schüle Daniel |
last post by:
Hello,
first question
In : cmp("ABC",)
Out: 1
against what part of the list is the string "ABC" compared?
second question
|
by: Lane Straatman |
last post by:
void s_sort(void *base, size_t nmemb, size_t size,
int (*compar)(const void *, const void *))
{
size_t bytes;
unsigned char *array, *after, *i, *j, *k, *p1, *p2, *end, swap;
array = base;...
|
by: sebastian.dau |
last post by:
Hello Newsgroup,
I have a link error that I did not manage to fix.
I basically consume a VC 8.0 C++ dll that exports a class with a
method containing CString declaration as follows:
class...
|
by: Bob Timpkinson |
last post by:
Hi,
I have a 32-bit machine... Is there anyway I can get gcc to use the
following integer sizes?
char: 8 bits
short: 16 bits
int: 32 bits
long: 64 bits
long long: 128 bits
|
by: Tim H |
last post by:
The following program compiles just fine in C, but not in C++. Can
anyone explain why? I have a chunk of code that defines stuff like
this in headers (without the extern) that I can not easily...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
| |