50分求助!

iLove9ouHenry 2012-02-25 05:21:30

// 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 buffer
char *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 qsort
void 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;
}


...全文
153 5 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
iLove9ouHenry 2012-02-25
  • 打赏
  • 举报
回复
读取一个文件,strtok分割拿到每个单词,存储在结构体的 ptr指针变量指向的地址中,然后用快速排序输出。
cao_julians 2012-02-25
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 liu518er 的回复:]
相当悲剧,没有main函数
[/Quote]
=======================
不对,int _tmain(int argc, _TCHAR* argv[])就是程序入口。不过有效语句被注释掉了,从system("pause")开始运行,就结束了。
liu518er 2012-02-25
  • 打赏
  • 举报
回复
相当悲剧,没有main函数
merlinfang 2012-02-25
  • 打赏
  • 举报
回复
想做啥
面包大师 2012-02-25
  • 打赏
  • 举报
回复
...什么问题?

70,022

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧