【发布时间】:2015-06-12 08:48:41
【问题描述】:
我正在尝试打开此文件 (final.txt) 并阅读内容:
我正在阅读的只是[PRTNUM]、[QUANTY]、[PONUMB]、[SERIAL]、[UNITS]。
我编写了以下 C 程序:
char* cStart = strchr(cString, '[');
if (cStart)
{
// open bracket found
*cStart++ = '\0'; // split the string at [
char* cEnd = strchr(cStart, ']');
// you could check here for the close bracket being found
// and throw an exception if not
*cEnd = '\0'; // terminate the keyword
printf("Key: %s, Value: %s",cString, cStart);
}
// continue the loop
但现在我想用第二个文件中的数据替换这些占位符:
132424235 004342 L1000 DZ12 234235 234235我想用132424235 替换[PRTNUM](来自第一个文件)等等......最后我的文件应该用所有这些数据更新。你能告诉我在上面的程序中我应该使用什么函数吗?
【问题讨论】:
标签: c string pointers file-io replace