Thread: Segmentation Fault :: Insertionsort Pointers

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Feb 2013
    Posts
    2

    Segmentation Fault :: Insertionsort Pointers


    Im pulling my hair out ,, can someone give me feedback on what errors i am making ???

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    using namespace std;
    
    void inssrt(void *akeys, int n, int size, int (*compare) (const void * , const void *))
    {
        register int i,j;
        char *keys;
        char *tmp;
    
        keys= (char *) akeys;
        tmp = (char *) malloc(size*sizeof(char));
        
        for(j=1;j<n;j++) {
        memcpy(tmp,&keys[(j)*size],size);
        i = j - 1;
        while(i >= 0 && (compare(&keys[(i) * size],&keys[(i+1)* size]) < 0)) {
            memcpy(&keys[(i+1) * size], &keys[(i) * size],size);
            i = i - 1;
        }
        memcpy(&keys[(i + 1) * size],tmp,size);
        }
        free ((char *)tmp);
    }
    Last edited by bgreen7887; 02-06-2013 at 03:46 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Strcat with pointers and Segmentation Fault
    By thames in forum C Programming
    Replies: 6
    Last Post: 12-02-2012, 06:48 AM
  2. Segmentation fault (strings, pointers, Linux)
    By ankushwrites in forum C Programming
    Replies: 2
    Last Post: 03-25-2012, 12:00 PM
  3. Replies: 8
    Last Post: 04-28-2008, 02:46 AM
  4. Segmentation fault with structs and char pointers
    By Keybone in forum C++ Programming
    Replies: 20
    Last Post: 01-17-2004, 01:36 PM
  5. segmentation fault - pointers/functions
    By p1c1078 in forum C Programming
    Replies: 15
    Last Post: 04-22-2003, 05:46 PM