亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費(fèi)注冊(cè) 查看新帖 |

Chinaunix

  平臺(tái) 論壇 博客 文庫(kù)
最近訪問(wèn)板塊 發(fā)新帖
查看: 2035 | 回復(fù): 2
打印 上一主題 下一主題

從文件讀取行,存儲(chǔ)于struct中,返回指針變量出錯(cuò),請(qǐng)大家?guī)涂纯?/a> [復(fù)制鏈接]

論壇徽章:
0
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報(bào)告]
發(fā)表于 2004-03-05 16:21 |只看該作者 |倒序?yàn)g覽
<code>;
#define _GNU_SOURCE
#include <stdio.h>;
#include <unistd.h>;
#include <string.h>;
#include <stdlib.h>;
#include <time.h>;
#include <signal.h>;



struct vgetconf {
  char *conf_card;                /* card  */
  char *conf_server_domain;                /* server domain name  */
  char *conf_clint_domain;                /* client domain name  */
char *conf_local_host;                /* localhost */
  char *conf_remote_host;                /* remote host */
   char *conf_local_area;                /*  localarea  */
   char *conf_remote_area;                /* remote area  */
};

struct vgetconf   *getline_b()

       {
struct vgetconf vgetconfs;
          FILE * fp;
            char * line = NULL;
            size_t len = 0;
            ssize_t read;
                        int i;
char *vget[6];

            fp = fopen("b.conf", "r";
            if (fp == NULL)
                 exit(EXIT_FAILURE);
            for(i=0;i<7;i++){
                read = getline(&line, &len, fp);      
                           vget=(char *)malloc(strlen(line)+1);     
                          strcpy(vget,line);   
                           }
            if (line)
                 free(line);
        vgetconfs.conf_card=vget[0];               
   vgetconfs.conf_server_domain=vget[1];               
   vgetconfs.conf_clint_domain=vget[2];               
   vgetconfs.conf_local_host=vget[3];               
   vgetconfs.conf_remote_host=vget[4];               
   vgetconfs.conf_local_area=vget[5];               
   vgetconfs.conf_remote_area=vget[6];
  return &amp;
       }


main()
{
struct vgetconf *vgetconfm;
vgetconfm=getline_b();


printf("%s \n", vgetconfm->;conf_card);
  printf("%s \n", vgetconfm->;conf_server_domain);
  printf("%s \n", vgetconfm->;conf_clint_domain);
  printf("%s \n", vgetconfm->;conf_local_host);
  printf("%s \n", vgetconfm->;conf_remote_host);
  printf("%s \n", vgetconfm->;conf_local_area);
  printf("%s \n", vgetconfm->;conf_remote_area);
  return EXIT_SUCCESS;

}
</code>;

b.conf內(nèi)容如下:
eth0
main.a.com
client.a.com
10.20.40.243
10.20.6.35
10.20.40.0
10.20.6.0


編譯信息:
gcc -o testfile testprintfi.c
testprintfi.c: In function `getline_b':
testprintfi.c:50: warning: function returns address of local variable
testprintfi.c:69:2: warning: no newline at end of file

執(zhí)行后,顯示到終端是三行亂碼
è™`üÿÃ 4
à'Bp]@°Â
xéÿ¿WB

論壇徽章:
1
榮譽(yù)版主
日期:2011-11-23 16:44:17
2 [報(bào)告]
發(fā)表于 2004-03-05 16:25 |只看該作者

從文件讀取行,存儲(chǔ)于struct中,返回指針變量出錯(cuò),請(qǐng)大家?guī)涂纯?/h2>
testprintfi.c:50: warning: function returns address of local variable
看這一句警告吧。不要說(shuō)你看不懂。
去你的程序那一行看看怎么回事。

論壇徽章:
0
3 [報(bào)告]
發(fā)表于 2004-03-05 16:42 |只看該作者

從文件讀取行,存儲(chǔ)于struct中,返回指針變量出錯(cuò),請(qǐng)大家?guī)涂纯?/h2>
static struct vgetconf vgetconfs;
大家以后別犯我同樣錯(cuò)誤咯~要注意變量生存期問(wèn)題和有效范圍!

希望此帖可對(duì)初學(xué)者讀取文件有參考作用!

OK!

您需要登錄后才可以回帖 登錄 | 注冊(cè)

本版積分規(guī)則 發(fā)表回復(fù)

  

北京盛拓優(yōu)訊信息技術(shù)有限公司. 版權(quán)所有 京ICP備16024965號(hào)-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號(hào):11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報(bào)專區(qū)
中國(guó)互聯(lián)網(wǎng)協(xié)會(huì)會(huì)員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關(guān)心和支持過(guò)ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請(qǐng)注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP