- 论坛徽章:
- 0
|
这个是我写的用C写的。应该是非常幼稚。
也贴出来,各位大侠,再帮我用C++写的同时,别忘了多多批评我这个版本!
文件的存储格式是:
name = TSV
age = 26
函数的功能是:
将文件里面的str项相匹配行的值提取出来,返回。
也就是如果str="name"则返回“TSV”
#include "readCnf.h"
#include <stdio.h>
char * readCnf(FILE *fp ,char * str)
{
char strTest[20];
char *sp=strTest;
int number,n;
char ch;
while (!feof)
{
while (ch!='\n')
{
ch=fgetc(fp);
*sp=ch;
sp++;
}
if ((number=strstr(strTest,str))!= NULL)
{
sp = strTest;
n=0;
while (n<number)
{
sp=*(sp+n);
sp++;
}
printf("%s",strTest);
return strTest;
}
sp = strTest; }
printf("%s",strTest);
return 0;
}
我在调用这个函数的时候就乱码。 |
|