【发布时间】:2019-11-20 18:31:49
【问题描述】:
我正在尝试获取文本文件中某一行的地址。此行包含以下内容;
亚利桑那州图森市东百老汇 7055 号凯马特
我正在使用 strcpy 和 strtok 函数来提取地址(7055 East Broadway),但到目前为止,我只能使用我的代码提取商店的名称(Kmart)。
char strLine[] 从文件中获取该行,我想将它返回给 char strAddress[]
如何仅提取地址以及可能的城市和州?
#define MAX_CHARS_PER_LINE 80
void getAddress(char strAddress[], const char strLine[])
{
char newLine[MAX_CHARS_PER_LINE+1];
strcpy(newLine,strLine);
char* token = strtok(newLine, ",");
strAddress = token;
printf("%s\n",strAddress);
}
【问题讨论】:
-
man strtok,在这里你可以找到一个使用
strtok的例子