程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程綜合問答 >> c語言問題-一個鏈表問題 是關於鏈表添加的 但是周圍的人每人能看出來問題

c語言問題-一個鏈表問題 是關於鏈表添加的 但是周圍的人每人能看出來問題

編輯:編程綜合問答
一個鏈表問題 是關於鏈表添加的 但是周圍的人每人能看出來問題

#include "common.h"
#include "config.h"
CONFIG_INFO_S srccon={0,NULL,NULL} ;

int vipp_config_add(char *buf)

{
char *delim= "=\n";
CONFIG_NODE_S plist;
strcpy(plist.key ,strtok(buf,delim));
strcpy(plist.value,strtok(NULL,delim));
if(srccon.head==NULL)
{
srccon.head=srccon.tail=&plist;
printf("1 printf is %s,value is %s\n",srccon.head->key,srccon.head->value);
}
else
{
srccon.tail->next =&plist;
srccon.tail=&plist;
printf("2 printf is %s,value is %s\n",srccon.tail->key,srccon.tail->value);
}
srccon.tail->next=NULL;
srccon.confignum++;
memset(buf,0,1024);
return 0;
}

int vipp_config_travser()
{
FILE *fp;
char buf[1024]={0};
strcpy(buf,"en.conf");
if(buf == NULL)
{
// printf("no this file\n");
exit (-1);
}
fp = fopen(buf,"r");
if(fp == NULL)
{
perror("fopen");
exit (-1);
}
while(fgets(buf,1024,fp))
{
vipp_config_add(buf);
}
return 0;
}
void travel()
{
CONFIG_NODE_S *plist=srccon.head;
while(plist!=NULL)
{
printf("key = %s,value = %s\n",plist->key,plist->value);
plist= plist->next;
}
}
主函數是
int main(void )
{
char tem[32]={0};
struct _config_node pre;
strcpy(tem,"config.cof");
vipp_config_travser();
travel();

return 0;

}要便利的文本是這個樣子的:welcomepro=Welcome
ipaddr=HostIPAddress
bcast=HostBcastAddress
nick=HostNickname
status=HostStatus
online=OnlineDevices
call=calls
message=messages
callwith=Callingwith
consolempt=vipp
nickname=OllyDbg
scaninter=2
autorecord=0
但是我怎麼也找不到自己出錯在哪裡,打印的結果完全不對,望諸位大神不吝賜教

最佳回答:


#include "common.h"
#include "config.h"
CONFIG_INFO_S srccon={0,NULL,NULL} ;

int vipp_config_add(char *buf)

{
char delim= "=\n";
*
*****CONFIG_NODE_S plist; 問題在這裡 由於這個是固定的地址 而且在不斷地調用,其地址是一直不變的,所以每次雖然添加了,但是都會被下一次覆蓋,所以,到了最後一直都是一個。
呵呵,以後切記,地址問題,內存分配特別重要

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved