c - The best way to print lines from an inputfile without '\n'? -
this question has answer here:
the task write c program print lines read input file (maybe very large), without '\n'
. please see comment in code below, typical way or way so??
int main() { const char *input_wavlist_file = "/home/legend0011/downloads/test-sample-list.txt"; const int buffer_size = 100; file *fr = fopen(input_wavlist_file, "r"); if (fr == null) { printf("error opening input wav list file!\n"); exit(1); } char str[buffer_size]; while((fgets(str, buffer_size, fr)) != null) { char *pch = strchr(str, '\n'); char *filepath = str; if (pch != null) *pch = '\0'; // typical way???????? printf("reading==>%s",filepath); } fclose(fr);
}
fgets()
comes newline character suppress newline , print it.
size_t n = strlen(str); if(n>0 && str[n-1] == '\n') { str[n-1] = '\0'; } printf("%s",str);
Comments
Post a Comment