当前位置:我的异常网» C语言 » 能不能帮忙改一下下面这些代码,原来是在windows系
能不能帮忙改一下下面这些代码,原来是在windows系统上运行的,要让它能在linux上终端跑。该如何处理
www.myexceptions.net 网友分享于:2013-04-13 浏览:10次
能不能帮忙改一下下面这些代码,原来是在windows系统上运行的,要让它能在linux上终端跑。
#include "stdio.h"
#include"stdlib.h"
#include"string.h"
#define LEN sizeof(struct word)
int main(int argc,char *argv[])
{
int i = 0;
FILE *fp;
char ch;
char string[50];
int len = 1;
int equal = 0;
int size = 0;
int max;
struct word
{
char str[50];
int num;
struct word *next;
struct word *pre;
};
struct word *list,*temp;
struct word *head,*com;
struct word *pre,*next,*wrap,*sea;
if(argc!= 2)
{
printf("输入格式不对,正确的格式为testWord filename!!!\n");
exit(0);
}
fp = fopen(argv[1],"r");
if(fp == NULL)
{
printf("文件打开错误!!!\n");
exit(0);
}
head = NULL;
list = temp = (struct word *)malloc(LEN);
ch = fgetc(fp);
for(i = 0;i<50;i++)
{
string[i] = '\0';
}
//读取文件,获取单词并统计该单词出现的次数
while(ch!=EOF)
{
if(!((ch >='A'&&ch<='Z')||(ch>='a'&&ch<='z')))
{
//判断单词是否已经出现过,出现过num+1,没出现的新增一个节点
if((string[0] >='A'&&string[0]<='Z')||(string[0]>='a'&&string[0]<='z'))
{
if(head != NULL)
{
com = head;
do
{
if(strcmp(string,com->str) == 0)
{
equal = 1;
break;
}
com = com->next;
}
while(com != NULL);
}
if(equal == 1)
{
//进行插入排序,如果数量增加,则调整相应的位置
com->num += 1;
equal = 0;
sea = head;
do
{
if(sea->num < com->num)
{
if(sea == head)
{
com->pre->next = com->next;
com->next->pre = com->pre;
com->pre = NULL;
com->next = sea;
sea->pre = com;
head = com;
}
else
{
pre = sea->pre;
pre->next = com;
sea->pre = com;
com->pre->next = com->next;
com->next->pre = com->pre;
com->pre = pre;
com->next = sea;
}
break;
}
sea = sea->next;
}
文章评论