C_and_CPP 板


LINE

我想要写一个程式 这个程式的动作是 void main() { FirstNode(); ReadCheater(); SortCheater(); //WriteCheater(); } 这是节点结构 struct Node { char Str[50]; unsigned int Length; struct Node *next; } *First, *Point, *SortedFirst; 函式内容: 建立一个新的节点 struct Node* NewNode(void) { struct Node *New; New = ( struct Node* )malloc(sizeof( struct Node)); New->next = NULL; return New; } 先建立两个空节点 一个是为排序的起始节点 一个是以排序的起始节点 void FirstNode(void) { First = NewNode(); SortedFirst = NewNode(); Point = First; } 读txt档里面的资料 每读一笔资料(字串) 就make一个新的节点出来储存 void ReadCheater(void) { FILE *fSource = fopen(" Path\\Cheater.txt","r"); struct Node *temp; char Str[100]; do{ temp = NewNode(); fscanf(fSource, "%s\n", &Str); if ((strcmp(Str, " ")==0)||(strcmp(Str, " ")==0)|| (strcmp(Str, "  "))==0) { fscanf(fSource, "%s", &Str); } strcpy( temp->Str, Str); temp->Length = strlen(Str); Point->next = temp; Point = Point->next; } while (!feof(fSource)); } 其中do while 里面的if 功能是在於: 如果读到程式认为是字串,但其实不是(换行、非中文或英文的"乱码") 就再读下一个字串。 这段我测试过了没什麽问题 问题在於下一个函式 之後作长度的排序(不作内容的排序) void SortCheater(void) { struct Node *temp; unsigned int Length = 0; FILE *fOutput = fopen("Path\\Sorted.txt","w"); temp = SortedFirst; Point = First; while (First->next == NULL){ Length++; while (Point->next != NULL){ if ( Point->next->Length == Length){ temp->next = Point->next; Point->next = Point->next->next; temp = temp->next; } else Point = Point->next; } Point = First; } temp = SortedFirst; do { fprintf(fOutput, "%s\n", temp->Str); temp = temp->next; } while (temp != NULL); fclose(fOutput); } 这里 我看了印出来的结果 是空字串(不像中文字的中文字,而且只有一行) 代表temp似乎没有指向SortedFirst这个空节点..... 为什麽会这样呢? 这里是我的原始资料: http://www.badongo.com/file/17096488 这是原始资料的来源: http://tw.csonline.gamania.com/event/20090901/090908_2.htm 因为我还不会读网路 所以先将就复制贴上在笔记本里 请乡民救救我的指标..... 除虫除了三天了..... 感激 <(_._)> -- 圣露西亚捐款10万美金 该国人口数仅17万 silverache:换算过来 平均每个国民捐给我们20几万台币~~啾感心LIONDODO:哇,一个人捐20几万… m7cord:好感动,一个人二十万耶。Q_Q --



※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 118.232.32.116 ※ 编辑: liu2007 来自: 118.232.32.116 (09/10 12:37)
1F:推 holymars:while (First->next == NULL) 09/10 12:57
2F:→ holymars:这个while loop根本不会进去吧 09/10 12:58
 \(" ̄口 ̄)/ 改成!=就可以了~ 我又耍笨了Orz.....感谢圣大!! 下面的图就不用看了XDDDDDDD (难得画图) ****************************************************************************** 经过ReadCheater()函式後 First Point ↓ ↓ ◎→█→█→█→█→█→█→█→█→█→█→█→NULL ****************************************************************************** SortCheater中的while开始前: First ↓ ◎→█→█→█→█→█→█→█→█→█→█→█→NULL ↑ Point SortedFirst ↓ ◎→NULL ↑ temp ****************************************************************************** ※ 编辑: liu2007 来自: 118.232.32.116 (09/10 13:15)
3F:推 holymars:对啊 First->next不是NULL 那while loop怎麽会跑呢 09/10 13:12
4F:推 Peruheru:While的()内条件「成立」才会「进入」,你搞颠倒了 09/10 13:13
5F:→ holymars:你用什麽IDE啊 学一下基本的debugger怎麽用吧XD 09/10 13:13
我是用VC++ 6.0 debugger是下面视窗的讯息吗?
6F:→ holymars:为这种bug花三天真是不值得XDDD 09/10 13:13
7F:→ Peruheru:要进入的条件要反过来写,=Null时离开就写成!=Null 09/10 13:14
※ 编辑: liu2007 来自: 118.232.32.116 (09/10 13:20)
8F:推 VictorTom:debugger, 就是环境给你的debug用的工具泛称吧.... 09/10 13:47
9F:→ VictorTom:比如用step by step一行一行trace, 搭配watch看变数, 09/10 13:47
10F:→ VictorTom:加入code break或data break point等等.... 09/10 13:47







like.gif 您可能会有兴趣的文章
icon.png[问题/行为] 猫晚上进房间会不会有憋尿问题
icon.pngRe: [闲聊] 选了错误的女孩成为魔法少女 XDDDDDDDDDD
icon.png[正妹] 瑞典 一张
icon.png[心得] EMS高领长版毛衣.墨小楼MC1002
icon.png[分享] 丹龙隔热纸GE55+33+22
icon.png[问题] 清洗洗衣机
icon.png[寻物] 窗台下的空间
icon.png[闲聊] 双极の女神1 木魔爵
icon.png[售车] 新竹 1997 march 1297cc 白色 四门
icon.png[讨论] 能从照片感受到摄影者心情吗
icon.png[狂贺] 贺贺贺贺 贺!岛村卯月!总选举NO.1
icon.png[难过] 羡慕白皮肤的女生
icon.png阅读文章
icon.png[黑特]
icon.png[问题] SBK S1安装於安全帽位置
icon.png[分享] 旧woo100绝版开箱!!
icon.pngRe: [无言] 关於小包卫生纸
icon.png[开箱] E5-2683V3 RX480Strix 快睿C1 简单测试
icon.png[心得] 苍の海贼龙 地狱 执行者16PT
icon.png[售车] 1999年Virage iO 1.8EXi
icon.png[心得] 挑战33 LV10 狮子座pt solo
icon.png[闲聊] 手把手教你不被桶之新手主购教学
icon.png[分享] Civic Type R 量产版官方照无预警流出
icon.png[售车] Golf 4 2.0 银色 自排
icon.png[出售] Graco提篮汽座(有底座)2000元诚可议
icon.png[问题] 请问补牙材质掉了还能再补吗?(台中半年内
icon.png[问题] 44th 单曲 生写竟然都给重复的啊啊!
icon.png[心得] 华南红卡/icash 核卡
icon.png[问题] 拔牙矫正这样正常吗
icon.png[赠送] 老莫高业 初业 102年版
icon.png[情报] 三大行动支付 本季掀战火
icon.png[宝宝] 博客来Amos水蜡笔5/1特价五折
icon.pngRe: [心得] 新鲜人一些面试分享
icon.png[心得] 苍の海贼龙 地狱 麒麟25PT
icon.pngRe: [闲聊] (君の名は。雷慎入) 君名二创漫画翻译
icon.pngRe: [闲聊] OGN中场影片:失踪人口局 (英文字幕)
icon.png[问题] 台湾大哥大4G讯号差
icon.png[出售] [全国]全新千寻侘草LED灯, 水草

请输入看板名称,例如:e-shopping站内搜寻

TOP