50分求助!
// Project3.cpp : Defines the entry point for the console application.//#include "stdafx.h"#include <string.h>#include <stdlib.h>#include <malloc.h>#include <assert.h>#include <conio.h>//read the file into bufferchar *readFile(const char *fileName){ assert(fileName !=NULL); FILE *pFILE = fopen(fileName, "rb"); char ch = fgetc(pFILE); assert(!feof(pFILE)); fseek(pFILE, 0, SEEK_END); long fileSize = ftell(pFILE); rewind(pFILE); //fseek(pFILEBuff, 0, SEEK_SET); char *pFILEBuff = (char*)malloc(sizeof(char)*fileSize); assert(pFILEBuff != NULL); size_t result = fread(pFILEBuff, 1, fileSize, pFILE); assert(result == fileSize); return pFILEBuff;}struct wordInfo{ char *pstr;};struct wordInfo *pWordInfo = (struct wordInfo*)realloc(pWordInfo, 100);//maybe wrong!!!void split(const char *fileName){ char *pFILEBuff = readFile(fileName); char *ptoken; ptoken = strtok(pFILEBuff," "); while(ptoken) { ptoken = strtok(NULL," "); char *pstring = NULL; realloc(pstring, sizeof(ptoken)); strcpy(pstring, ptoken); pWordInfo->pstr = pstring; }}//must use qsortvoid wordsort(){ qsort (void * base, size_t nmem, size_t size , comp) ; //call this //output results}int comp(const void *p, const void *q) { return (*( int*)p - *(int*)q) ; }int _tmain(int argc, _TCHAR* argv[]){ /* char *fileName; split(fileName); wordsort(); */ system("pause"); return 0;}