473,394 Members | 1,746 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

sort.c(13) : error C2371: 'shellSort' : redefinition; different basic types

9
program in C, shell sort.

i've got this error : sort.c(13) : error C2371: 'shellSort' : redefinition; different basic types

Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2.  
  3. int a[6] = {5, 9 , 2, 8, 7, 1};
  4. int main(){
  5.     int m;
  6.     m = 0;
  7.     shellSort(a, 6);
  8.     for(m = 0; m<20; m++)
  9.         printf("\n%d", a[m]);
  10.  
  11.     return 0;
  12. }
  13. void shellSort( int a[],int N){
  14.     int i, j, inc;
  15.     int tmp;
  16.     for(inc = N/2; inc>0; inc /= 2)
  17.         for(i = inc; i < N; i ++)
  18.         {
  19.             tmp = a[i];
  20.             for(j = i; j>= inc; j -= inc)
  21.                 if(tmp <a[j-inc])
  22.                     a[j] = a[j - inc];
  23.                 else 
  24.                     break;
  25.             a[j] = tmp;
  26.         }
  27.  
  28. }
  29.  
May 23 '10 #1

✓ answered by Banfa

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.
May 23 '10 #2
AlexC
9
Thanks, I need to study so much. I didn't know that.
this is fixed up code
Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2.  
  3. int a[6] = {5, 9 , 2, 8, 7, 1};
  4. int main(){
  5.     int m;
  6.     m = 0;
  7.     printf("Unsorted list:");
  8.     for(m = 0; m<6; m++)
  9.         printf("\n%d", a[m]);
  10.     shellSort(a, 6);
  11.     printf("\nShell Sorted: ");
  12.     for(m = 0; m<6; m++)
  13.         printf("\n%d", a[m]);
  14.  
  15.     return 0;
  16. }
  17. int shellSort( int a[],int N){
  18.     int i, j, inc;
  19.     int tmp;
  20.     for(inc = N/2; inc>0; inc /= 2)
  21.         for(i = inc; i < N; i ++)
  22.         {
  23.             tmp = a[i];
  24.             for(j = i; j>= inc; j -= inc)
  25.                 if(tmp <a[j-inc])
  26.                     a[j] = a[j - inc];
  27.                 else 
  28.                     break;
  29.             a[j] = tmp;
  30.         }
  31. return 0;
  32. }
  33.  
May 23 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
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...
27
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...
2
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...
3
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...
1
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...
4
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
31
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;...
4
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...
159
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
11
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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...
0
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...
0
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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...
0
marktang
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,...
0
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...
0
Oralloy
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,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.