gpt4 book ai didi

c - 从 char* 的末尾去除换行符

转载 作者:太空宇宙 更新时间:2023-11-04 06:19:10 26 4
gpt4 key购买 nike

<分区>

我有一个 char* 行,我在上面使用了 while (fgets(line, line_size, fNames) != NULL)。现在的问题是我也得到了一个换行符,我想去掉它。

#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>

int main() {
int i;
char fileName[30];
FILE *fNames, *fCurrent;
char *line = NULL, command[100];
char letters3[3];
size_t len = 0;
//size_t read;
const size_t line_size = 300;
line = malloc(line_size);
if (access("fileNames.lst", F_OK) == -1)
system("crunch 3 3 abcd -o fileNames.lst");
else
printf("fileNames.lst already exists.\n");
fNames = fopen("./fileNames.lst","r");

while (fgets(line, line_size, fNames) != NULL) {
printf("Making File: %s.lst\n", line);
strcpy(command, "crunch 8 8 -t ");
strcpy(command, line);
strcpy(command, strcat(command," -o"));
puts(command);
strcpy(line, strcat(line, ".lst"));
fCurrent = fopen(line, "w");
//system(command);
fclose(fCurrent);
//system("read -r -p \"Press space to continue...\" key");
}
return 0;
}

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com