Pointer Problems again

This is a discussion on Pointer Problems again within the C Programming forums, part of the General Programming Boards category; hey, i have a pointer problem with my compare function. Code: int dataComp( const void * a, const void * ...

  1. #1
    Registered User chriscolden's Avatar
    Join Date
    Jan 2006
    Posts
    32

    Pointer Problems again

    hey,

    i have a pointer problem with my compare function.

    Code:
    int dataComp( const void * a, const void * b ) {
    	float * arg1, arg2;
    
    	comps++;
    	
    	arg1 = (float*) a;
    	arg2 = (float*) b;
    	
    	if( *arg1 < *arg2 ) return -1;
    	else if( *arg1 == *arg2 ) return 0;
    	else return 1;
    }
    this function is ment to compare the data for use with qsort and some of my own sorting functions. comps++; is used as a counter for testing purposes.

    any ideas why i'm getting the following errors....
    Illegal use of floating point
    arg1 is assign a value that is never used
    Parameter 'b' is never used.

    Thanks once again for all the great help you all provide.

    Cheers

    Chris
    I'm a noob when it comes to C and I have to use Borland C++ 3.1 because my university won't move on.

    However I do use Turbo C++ 3.1 for windows. Makes life abit less stressful.

  2. #2
    Registered User
    Join Date
    Apr 2006
    Posts
    2,041
    Arg2 is a float, not a float pointer. To make it a pointer do:
    float * arg1, *arg2;

    That should solve your problem.
    It is too clear and so it is hard to see.
    A dunce once searched for fire with a lighted lantern.
    Had he known what fire was,
    He could have cooked his rice much sooner.

  3. #3
    Registered User chriscolden's Avatar
    Join Date
    Jan 2006
    Posts
    32
    thanks, sorted out all the errors. cheers
    I'm a noob when it comes to C and I have to use Borland C++ 3.1 because my university won't move on.

    However I do use Turbo C++ 3.1 for windows. Makes life abit less stressful.

  4. #4
    Registered User
    Join Date
    May 2006
    Posts
    903
    I'm a noob when it comes to C and I have to use Borland C++ 3.1 because my university won't move on.

    However I do use Turbo C++ 3.1 for windows. Makes life abit less stressful.
    It's a joke right ? I know it's a sig so it must be. If it's not... well download Dev-C++ and you'll go straight to heaven

  5. #5
    Registered User chriscolden's Avatar
    Join Date
    Jan 2006
    Posts
    32
    nope its true, we have to make sure it runs on borland c 3.1 for dos as that is the only thing our university will use to teach us.

    i'm all for using better development enviroments, i think 1/2 of my problems are the result of the crap debugger in borland c 3.1 for dos.

    If anyone knows if this dev-c++ is good for developing c programms that will compile and run ok in borland 3.1, can you post a link for me to download it.

    thanks

    Chris
    I'm a noob when it comes to C and I have to use Borland C++ 3.1 because my university won't move on.

    However I do use Turbo C++ 3.1 for windows. Makes life abit less stressful.

  6. #6
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    http://www.bloodshed.net/devcpp.html

    If you write Standard C, the code should compile on any compiler.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  7. #7
    Registered User cDev's Avatar
    Join Date
    Jun 2006
    Posts
    26
    Quote Originally Posted by chriscolden
    nope its true, we have to make sure it runs on borland c 3.1 for dos as that is the only thing our university will use to teach us.
    How annoying is that? When I was in undergrad my college forced us to purchase Microsoft Visual Studio, and it turned me off from programming because I hated using it. Now Linux has helped me to enjoy programming again
    P.S. Dev-C++ rules. You should have no problem doing all your development with it. Then I reccomend you just do a quick compile in Boreland before you have to submit your assignments (to be on the safe side.)

  8. #8
    Registered User
    Join Date
    Mar 2006
    Posts
    725
    Dev-C++ is excellent, but development has stalled. You may also want to try out Code::Blocks.
    Code:
    #include <stdio.h>
    
    void J(char*a){int f,i=0,c='1';for(;a[i]!='0';++i)if(i==81){
    puts(a);return;}for(;c<='9';++c){for(f=0;f<9;++f)if(a[i-i%27+i%9
    /3*3+f/3*9+f%3]==c||a[i%9+f*9]==c||a[i-i%9+f]==c)goto e;a[i]=c;J(a);a[i]
    ='0';e:;}}int main(int c,char**v){int t=0;if(c>1){for(;v[1][
    t];++t);if(t==81){J(v[1]);return 0;}}puts("sudoku [0-9]{81}");return 1;}

  9. #9
    Registered User
    Join Date
    Mar 2005
    Posts
    135
    I personally recommend Visual C++ 2005 Express Edition . It's free also , Just don't forget to create your source files with the .c extension or they'll default to .cpp (c++).

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problems with passing an array of structures by pointer
    By raptor1770 in forum C Programming
    Replies: 9
    Last Post: 11-29-2008, 10:01 AM
  2. Replies: 2
    Last Post: 07-11-2008, 07:39 AM
  3. Following CTools
    By EstateMatt in forum C Programming
    Replies: 5
    Last Post: 06-26-2008, 10:10 AM
  4. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 09:33 AM
  5. base class pointer problems
    By ... in forum C++ Programming
    Replies: 3
    Last Post: 11-16-2003, 10:27 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21