+ -
当前位置:首页 → 问答吧 → 读取文件出问题

读取文件出问题

时间:2010-07-28

来源:互联网

  1. void initializationconf()
  2. {
  3.         FILE *fp;
  4.         int ch[50] = {0x00, 0x00};
  5.         char *tmp[200];
  6.         int in=0;
  7.             char dictionary[300];
  8.         memset(dictionary, '\0', 300);

  9.         fp=fopen("config.conf","r");
  10.        
  11.          if(fp)
  12.          {
  13.                 while ((ch[0] = fgetc(fp)) != EOF)
  14.                 {
  15.                         strcat(dictionary,(char *)ch);
  16.                 }
  17.                 fclose(fp);
  18.                
  19.                 char * str=strdup((char*)&dictionary);
  20.                 printf("%s\n",str);//这里输出正常
  21.                 char *out1=NULL;
  22.                 while((tmp[in]=strtok_r(str,";",&out1))!=NULL)
  23.                 {
  24.                        printf("%s\n",(char*)&tmp[in]);//这里输出乱码
  25.                         in++;
  26.                         str=NULL;
  27.                 }
  28.                 printf("%i\n",in);//这里输出正常
  29.          }
  30. }
复制代码
这是输出结果

[root@test /]# ./t         
MAPSUM=10;SERVER_IPS=192.168.1.3;MEMPORT=11211;SOCKETPORT=4502;ONLINE=3000THREAD_THREADS_MAX=1;GOTOXY=1;ROLE_MOVE_TIME=1;CHAT_TIME=2;MOVE_SPEED=10;ROUND_TIME=12;
3
3
5p
Q3
h3
v3
???·
?3
¨4
±3
??
?3
?3
?
12 //这个是printf("%i\n",in);这个输出的正常

作者: jd808   发布时间: 2010-07-28

printf("%s\n",(char*)&tmp[in]);//这里输出乱码
--》
printf("%s\n",tmp[in]);//这里输出乱码

作者: hellioncu   发布时间: 2010-07-28

相关阅读 更多

热门下载

更多