首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 操作系统 > UNIXLINUX >

资料終端显示问 题

2012-11-03 
文件終端显示问 题程序如 下 :#includestdio.h#includefcntl.h#includestdlib.hint main(){int pch

文件終端显示问 题
程序如 下 :
#include<stdio.h>
#include<fcntl.h>
#include<stdlib.h>
int main()
{
  int p;
  char buf[2048];
  int flag;
  if((p=open("text",O_RDWR))==-1)
  {
  printf("file open error\n!");
  exit(-1);
  }else
  {
  if((flag=read(p,buf,2048))==-1){
  printf("read fail,try again\n");
  exit(-1);
  }
  else
  write(STDOUT_FILENO,buf,2048);
  }
  return 0;
}
cc rw.c
./a.out
显示:? ELF0m4|g4 linux-c$ a.out
(ED444@@???????(?(?1?1?1?'?W|M|M|M??tttDD?1?1?1@P?td??????,3,3Q?tdR?td?1?1?1,???)???'????4??(??6?)??? i|????%?w ?w ?i-laptop:~/linux-c$ ./a.out
|???|???(????0&?B$?+??|????)???????P(????? ??r8$?????|?P$???|??$|?|??E? 4C???)??? |????|$?
@)??R0)??4C$)??T
|?$?D???(????)??$)??0)??p$?)???E$?? ??o????)????
?)??&?w ???Ha?<?$?D?)??F?)???B4C? ii
|?|???|?|?|????%????P%??A,?
?(*??@)??????4*???? ?E?????l*??????*?,}0?,<*????? |?
GEdP.?)WO_? |?.N=?H
  P1m5? |?|???? ,???P+???
$+??R+??,+??T
H
  |????????B??*??? ??????*????? ???*??9?$????? ??*???D?? +?
请问何解?

[解决办法]

C/C++ code
else  write(STDOUT_FILENO,buf,2048);
[解决办法]
write(STDOUT_FILENO,buf,2048);

文件里的内容不一定全是可显示的字符,可以用记事本打开看一下
[解决办法]
可能是编码的问题。把ssh客户端的编码改成UTF-8试试。
[解决办法]
貌似是编码问题

热点排行