我正在尝试检测明文的哪些行以“linePrefix”开头。使用上面的代码,即使有巧合,strcmp
也永远不会返回 0。有谁知道我在哪里失败?
const char PREFIX[] = {"linePrefix"};
FILE *fp;
char *line = NULL;
char *aux = NULL;
aux = (char *) malloc(16);
size_t len = 0;
ssize_t read;
char path[] = {/*path*/};
fp = fopen(path, "r");
while ((read = getline(&line, &len, fp)) != -1) {
strncpy(aux, line, 15);
printf("strcmp: %i\n, strcmp(aux, PREFIX));
}