标签:memcpy etc console 核心 for class OLE file 获取
假如分割符文件为
11 22 33
44 55 66
只获取33,66数据,代码如下,核心利用fgets读取到回车终止
#include <sys/types.h>
#include <stdio.h>
#include <stdbool.h>
#define MAX_LEN 1024
bool ReadFile(char* filePath);
int main(int argc, char** argv)
{
char* src = "//root//projects//ConsoleApplication3//src.txt";
ReadFile(src);
getchar();
return 0;
}
bool ReadFile(char* filePath)
{
char src[MAX_LEN];
char dst[MAX_LEN];
FILE* fp = fopen(filePath, "r");
if (!fp)
{
printf("can‘t open file\n");
return false;
}
while (!feof(fp)) {
memset(src, 0x00, MAX_LEN);
fgets(src, MAX_LEN, fp );
int lineLength = strlen(src);
int iLastPosSpace=0;
for (int j = lineLength - 1; j >= 0; j--)
{
if (src[j] == ‘ ‘)
{
memset(dst, 0x00, MAX_LEN);
iLastPosSpace = j;
memcpy(dst, src+iLastPosSpace+1, lineLength-iLastPosSpace+1);
printf(dst);
break;
}
}
}
fclose(fp);
return true;
}
标签:memcpy etc console 核心 for class OLE file 获取
原文地址:https://www.cnblogs.com/zhaogaojian/p/14537135.html