本文介绍了值未从链接列表返回的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 大家好, 我的问题是我的程序在一个文件中工作而在文件之间不起作用。有人可以对它进行一些说明。 ifd = open( SERVER.CFG,O_RDONLY); while ((retin = read(ifd,& str, 650 ))> 0 ) { // i = 1; printf( String is =%s ,STR); pch = strtok(str, \ n); while (pch!= NULL) { printf( IN:%s \ n,pch); pch = strtok(NULL, = \ n); if (pch [ 0 ] == ' E') break ; printf( pch =%s,pch); if (pch [ 0 ]!= ' [') add_to_list(pch, true ); // printf(Key is:=%s,pch); } } close(ifd); struct data_struct * head = NULL; struct data_struct * ptr = head; ptr = search_in_list( clientip,NULL) ; if (ptr!= NULL) { printf( \ nClientIp:%s \ n,ptr-> val); ip = ptr-> val; } else { printf( 无法找到ClientIp来连接\ n); // exit(0); } 以上代码适用于同一档案。 但是当我把上面的代码添加到文件中的链接列表并在其他文件中搜索时这不起作用并且搜索列表功能无法返回任何值。 知道为什么会这样吗?????? 我有2个文件:server.c和comfunc .c 当我把我的整个代码放在任何一个文件中它工作正常但是当我把我的代码分开说 addlist in comfunc .c和 server.c中的搜索列表 它不起作用。 来自搜索列表的值不是回来得当。它返回NULL指针。 但是当在同一文件中搜索完成并返回搜索到的值时。解决方案 我有2个文件:server.c和comfunc.c 当我把我的整个代码放在任何单个文件中它工作正常但是当我将我的代码分开时说 comfunc.c中的addlist和 server.c中的搜索列表 它不起作用。值未正确返回。它返回NULL指针。 但是当在同一文件中搜索完成并返回搜索到的值时。 Hi guys,I have a problem the my program works in one file and does not work in between files. Can some one throw some light on it.ifd= open("server.cfg",O_RDONLY); while((retin = read(ifd,&str,650)) > 0 ) { //i=1; printf("String is = %s",str); pch = strtok (str," \n"); while (pch != NULL) { printf ("IN:%s\n",pch); pch = strtok(NULL," =\n"); if ( pch[0] == 'E') break; printf("pch =%s",pch); if ( pch[0] != '[') add_to_list(pch,true); //printf("Key is:=%s",pch); } } close(ifd); struct data_struct *head = NULL; struct data_struct *ptr = head; ptr = search_in_list("clientip", NULL); if ( ptr != NULL) { printf("\nClientIp:%s\n",ptr->val); ip = ptr->val; } else { printf("Can't Find ClientIp to connect\n"); //exit(0); }Above code works when put in same file.But when I put above code of adding in link list in file and searching in other file this does not work and search list function fails to return any values.Any idea why so ??????I have 2 files : server.c and comfunc.cwhen i put my whole code in any single file it works fine but when i divide my code in sayaddlist in comfunc.c andsearchlist in server.cit does not work.values from searchlist are not returned properly. it returns NULL pointer.but when in same file search completes fine and returns the searched value. 解决方案 I have 2 files : server.c and comfunc.cwhen i put my whole code in any single file it works fine but when i divide my code in sayaddlist in comfunc.c andsearchlist in server.cit does not work.values from searchlist are not returned properly. it returns NULL pointer.but when in same file search completes fine and returns the searched value. 这篇关于值未从链接列表返回的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
09-26 20:31