#include "stdio.h"
#include "iostream.h"
#include "string.h"
char* GetTablename(char *FilePath, char *TableName)
{
FILE *fp1;
char line[100];
char *p;
bool bol = false;
fp1 = fopen( FilePath, "r" );
while(!feof(fp1))
{
if( fgets( line, 100, fp1 ) == NULL)
return NULL;
p = strtok(line, " ");
if (strcmp(p, TableName) == 0)
{
bol = true;
}
p = strtok(NULL, " ");
if(bol)
{
return p;
}
}
fclose(fp1);
return NULL;
}
void main()
{
char *q;
q = GetTablename( "D:\\111.txt", "tablename1");
cout<< q << endl;
}
输出是9@
应该是aaa 啊
D:\\111.txt
tablename1 aaa
tablename2 bbb
改变了下TXT的数,还是错的