strange arrow when reading file
Posté le 17/12/2023 15:11
when i print the file line by line i got this arrows in the end of every line (except the last one)
FILE *file;
char line[150];
file = fopen(CatPath, "r");
if (file == NULL) {
perror("Error opening file");
return 1;
}
while (fgets(line, sizeof(line), file) != NULL) {
print_txt(scr, line-1, x_scrl, y_scrl);
}
fclose(file);
i tried also the BFile_Open
int file_descriptor = BFile_Open(file_path, BFile_ReadOnly);
if (file_descriptor == -1) {
print_txt(scr, "Error opening file", x_scrl, y_scrl);
return;
}
// Read and print the file content
char buffer[ BFile_Size(file_descriptor)+1];
ssize_t bytesRead;
bytesRead = BFile_Read(file_descriptor, &buffer, sizeof(buffer), 0);
if (bytesRead == -1) {
print_txt(scr, "Error reading file", x_scrl, y_scrl);
// Handle error if necessary
return;
}
int close_status = BFile_Close(file_descriptor);
// Close the file
if (file_descriptor >= 0) {
if (close_status < 0) {
print_txt(scr, "Error closing file", x_scrl, y_scrl);
return;
// Handle error if necessary
}
}
char *tok, *buff_p;
buff_p=buffer;
while ((tok = strsep(&buff_p, "\n")) != NULL) {
print_txt(scr, tok, x_scrl, y_scrl);
}
it also give me same thing but only 1 arrow
Fichier joint
Citer : Posté le 17/12/2023 15:15 | #
By arrow you mean this symbol: "↲"?
This is due to two things. One, the \n (newline characters) at the end of each line are placed into your buffer by fgets(), which is the expected result. Two, your function print_txt() uses a text printing function like dtext() that prints all characters, including newline, verbatim.
If you want a console/shell that goes to the next line when the character \n is printed, then you should handle that manually. Other features in the same category usually include word wrapping, scrolling, etc. which dtext() does not handle.
Citer : Posté le 17/12/2023 15:21 | #
By arrow you mean this symbol: "↲"?
This is due to two things. One, the \n (newline characters) at the end of each line are placed into your buffer by fgets(), which is the expected result. Two, your function print_txt() uses a text printing function like dtext() that prints all characters, including newline, verbatim.
If you want a console/shell that goes to the next line when the character \n is printed, then you should handle that manually. Other features in the same category usually include word wrapping, scrolling, etc. which dtext() does not handle.
i still have the up arrow , is it "\0" ?
Citer : Posté le 17/12/2023 15:24 | #
Nope, \0 indicates the end of the string so it's not printed. That's another character called "carriage return" which is written \r.
This is due to a difference between Windows and Linux. On Linux when you save a file each newline is saved as \n (one character). On Windows it is saved as \r\n (two characters). You should treat the sequence \r\n as identical to a single \n, i.e. it's a newline.
gint's font uses the spot for \r for this up arrow out of convenience because \r is not printed normally.
Citer : Posté le 17/12/2023 15:46 | #
Nope, \0 indicates the end of the string so it's not printed. That's another character called "carriage return" which is written \r.
This is due to a difference between Windows and Linux. On Linux when you save a file each newline is saved as \n (one character). On Windows it is saved as \r\n (two characters). You should treat the sequence \r\n as identical to a single \n, i.e. it's a newline.
gint's font uses the spot for \r for this up arrow out of convenience because \r is not printed normally.
I'm starting to hate Windows
Thank you, that worked, I activated cat and bash function
By the way, is there a place to ask questions for people with many questions like me? Should I stay on the forum?
Citer : Posté le 17/12/2023 15:56 | #
Good work! Please feel free to ask any questions on the forum, this is the correct place. If you have many questions related to one project like your shell/terminal here, you can create a topic for that project and ask there. Then you can also use the topic to announce updates, show screenshots, etc.
Citer : Posté le 17/12/2023 16:00 | #
Good work! Please feel free to ask any questions on the forum, this is the correct place. If you have many questions related to one project like your shell/terminal here, you can create a topic for that project and ask there. Then you can also use the topic to announce updates, show screenshots, etc.
Thanks Bro.