对file data 的testing

/*前提:测试所用文件:certus.ini

data如下:

[CERTUSINFORMATION]
STUNSERVER=xx
ACSSERVERURL=http://xx.

*/

 

 

/*对certus.ini读写进行的测试 测试需要ini文件内容*/ #include <stdio.h> #include <string.h> #include <unistd.h> int main(){ FILE *_fd=NULL; _fd=fopen("certus.ini","r"); if(_fd==NULL) printf("open error/n"); printf("open success/n"); char buff[222]; memset(buff,0x00,sizeof(buff)); int i=0; while(fgets(buff,222,_fd)!=NULL){ char *ptr1=NULL; char* ptr2=NULL; void *object=NULL; char tmp[128]; if(!strncmp(buff, "ACSSERVERURL", 12)) {printf("%d->/n",i++); } else if(!strncmp(buff, "STUNSERVER", 10)) printf("%d->/n",i++); else continue; if(!(ptr1 = strchr(buff, '='))){ printf("no match symbol/n"); break; } ptr1++; ptr2=tmp; while((*ptr1) != '/n' && (*ptr1) !='/0' && (*ptr1) != '/r') { (*ptr2++) = (*ptr1++); } (*ptr2) = '/0'; //strcpy((char *)object, tmp);//happen frament illegal,but why the next func not so? printf("xx %s/n",tmp); } getch(); return 0; }

 

 

/*对certus.ini读写进行的测试 测试需要ini文件内容 进一步的测试 */ #include <stdio.h> #include <string.h> #include <unistd.h> typedef enum{ asc=0x01, stun=0x02 }_type; static int _analys(char *acsUrl,char* stunServerAddr,const char* initFileUrl){ FILE *_fd=NULL; _fd=fopen(initFileUrl,"r"); if(_fd==NULL) printf("open error/n"); printf("open success/n"); char buff[222]; memset(buff,0x00,sizeof(buff)); int i=0; while(fgets(buff,222,_fd)!=NULL){ char *ptr1=NULL; char* ptr2=NULL; void *object=NULL; char tmp[128]; _type type; if(!strncmp(buff, "ACSSERVERURL", 12)) {printf("%d->/n",i++); type=asc; object=(void*)acsUrl; } else if(!strncmp(buff, "STUNSERVER", 10)) {printf("%d->/n",i++);object=(void*)stunServerAddr; type=stun; } else continue; if(!(ptr1 = strchr(buff, '='))){ printf("no match symbol/n"); break; } ptr1++; ptr2=tmp; while((*ptr1) != '/n' && (*ptr1) !='/0' && (*ptr1) != '/r') { (*ptr2++) = (*ptr1++); } (*ptr2) = '/0'; //strcpy((char *)object, tmp);//happen frament illegal,but why the next func not so? printf("xx %s/n",tmp); strcpy((char *)object, tmp); } } int main(){ char *acsUrl; char* stunServerAddr; _analys(acsUrl,stunServerAddr,"certus.ini"); getch(); return 0; }

你可能感兴趣的:(object,File,测试,null,ini,testing)