首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

能不能帮忙改一下下面这些代码,原来是在windows系统上运行的,要让它能在linux上终端跑。该如何处理

2012-04-12 
能不能帮忙改一下下面这些代码,原来是在windows系统上运行的,要让它能在linux上终端跑。#include stdio.h

能不能帮忙改一下下面这些代码,原来是在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;
  }


  while(sea != NULL);
  }
  else
  {
  strcpy(list->str,string);
  list->num = 1;
  list->next = NULL;
  if(head == NULL)
  {
  list->pre = NULL;
  head = list;
  }
  else
  {
  temp->next = list;
  list->pre = temp;
  }
  temp = list;
  list = (struct word *)malloc(LEN);
  len += 1;
  }

  for(i = 0;i<50;i++)
  {
  string[i] = '\0';
  }
  size = 0;
  }
  }
  else
  {
  string[size] = ch;
  size += 1;
  }
  ch = fgetc(fp);
  }


  //将链表信息输出
  printf("单词\t次数\t\n");
  if(head != NULL)
  {
  com = head;
  do
  {
  printf("%s\t%d\t\n",com->str,com->num);
  com = com->next;
  }
  while(com != NULL);
  }

  fclose(fp);

return 0;

}


[解决办法]

探讨
引用:

都是C的库函数,拿过去不能跑?


不能的样子诶,

会输出
Segmentation fault

[解决办法]
你程序有问题,在Windows下就直接死了。可能是你测试的文件不一样导致的吧。我在我电脑上随便弄了个英文文本文件就死了。直接检查别人的代码是件很头痛的事
[解决办法]
都是标准库,如果程序没问题的话应该直接编译了就能跑的
[解决办法]
与平台无关, 程序本身有问题。 这样让别人该你的代码太费劲了, 还是把最原始题目的要求贴出来吧!

热点排行