split file in c error get buffer in readfile
===

I program a program to split file in C in Ubuntu.
I have error when get buffer in readfile.
here is my code.   

        int split(char *filename, unsigned long part) {
        	FILE *fp;
        	char *buffer;
        	size_t result; // bytes read
        	off_t fileSize;
        
        	fp = fopen(filename, "rb");
        	if (fp == NULL) {
        		fprintf(stderr, "Cannot Open %s", filename);
        		exit(2);
        	}
        // Get Size
        	fileSize = get_file_size(filename);
        // Buffer
        	buffer = (char*) malloc(sizeof(char) * (fileSize + 1));
        	if (buffer == NULL) {
        		fputs("Memory error", stderr);
        		fclose(fp);
        		return 1;
        	}
        // Copy file into buffer
        //char buffers[11];
        	result = fread(buffer, 1, fileSize, fp);
        	buffer[fileSize] = '\0';
        
        	if (result != fileSize) {
        		fputs("Reading error", stderr);
        		return 1;
        	}
        
        // Split file
        	off_t partSize = fileSize / part;
        // Last Part
        	off_t lastPartSize = fileSize - partSize * part;
        	unsigned long i;
        	unsigned long j;
        	// create part 1 to n-1
        	for (j = 0; j < part; j++) {
        		char partName[255];
        		char *content;
        		char partNumber[3];
        		// Content of file part
        //		for (i = j; i < partSize * (j + 1); i++) {
        //
        //		}
        		content = (char*) malloc(sizeof(char) * partSize);
        		content = copychar(buffer, j + i, partSize + i);
        		i += partSize;
        		//copy name
        		strcpy(partName, filename);
        		// part Number
        		sprintf(partNumber, "%d", j);
        		// file name with .part1 2 3 4 ....
        		strcat(partName, ".part");
        		strcat(partName, partNumber);
        		// Write to file
        		writeFile(partName, content);
        		free(content);
        	}
        // last part
    	char *content;
    	content = (char*) malloc(sizeof(char) * (fileSize - partSize * (part - 1)));
    	content = copychar(buffer, (part - 1) * partSize + 1, fileSize);
    	char lastPartNumber[3];
    	char lastPartName[255];
    	sprintf(lastPartNumber, "%d", part);
    	strcpy(lastPartName, filename);
    	strcat(lastPartName, ".part");
    	strcat(lastPartName, lastPartNumber);
    	writeFile(lastPartName, content);
    	free(content);
    
    	free(buffer);
    	fclose(fp);
    	return 0;    
    }


here is function copychar from start to end

    char *copychar(char* buffer, unsigned long start, unsigned long end) {
    	if (start >= end)
    		return NULL;
    	char *result;
    	result = (char*) malloc(sizeof(char) * (end - start) + 1);
    	unsigned long i;
    	for (i = start; i <= end; i++)
    		result[i] = buffer[i];
    	result[end] = '\0';
    	return result;
    }

here is function to get filesize

    off_t get_file_size(char *filename) {
    	struct stat st;
    	if (stat(filename, &st) == 0)
    		return st.st_size;
    	fprintf(stderr, "Cannot determine size of %s: %s\n", filename);
    	return -1;
    }

here is function to write file

        int writeFile(char* filename, char*buffer) {
    	if (buffer == NULL || filename == NULL)
    		return 1;
    	FILE *file;
    	file = fopen(filename, "wb");
    	fwrite(buffer, sizeof(char), sizeof(buffer) + 1, file);
    	fclose(file);
    	return 0;
    }



When I test I use file test 29MB and it dumped.
I debug It return fileSize true but when readfile in buffer get from file it only return 135 characters and when use copychar it error.
I don't know how to devide buffer into part to write into part when split.
Thank for advance!