Les membres ayant 30 points peuvent parler sur les canaux annonces, projets et hs du chat.
La shoutbox n'est pas chargée par défaut pour des raisons de performances. Cliquez pour charger.

Forum Casio - Discussions


Index du Forum » Discussions » strange arrow when reading file
Zaky202 Hors ligne Membre Points: 35 Défis: 0 Message

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


Lephenixnoir Hors ligne Administrateur Points: 24240 Défis: 170 Message

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.
Mon graphe (11 Avril): ((Rogue Life || HH2) ; PythonExtra ; serial gint ; Boson X ; passe gint 3 ; ...) || (shoutbox v5 ; v5)
Zaky202 Hors ligne Membre Points: 35 Défis: 0 Message

Citer : Posté le 17/12/2023 15:21 | #


Lephenixnoir a écrit :
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" ?
Lephenixnoir Hors ligne Administrateur Points: 24240 Défis: 170 Message

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.
Mon graphe (11 Avril): ((Rogue Life || HH2) ; PythonExtra ; serial gint ; Boson X ; passe gint 3 ; ...) || (shoutbox v5 ; v5)
Zaky202 Hors ligne Membre Points: 35 Défis: 0 Message

Citer : Posté le 17/12/2023 15:46 | #


Lephenixnoir a écrit :
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?
Lephenixnoir Hors ligne Administrateur Points: 24240 Défis: 170 Message

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.
Mon graphe (11 Avril): ((Rogue Life || HH2) ; PythonExtra ; serial gint ; Boson X ; passe gint 3 ; ...) || (shoutbox v5 ; v5)
Zaky202 Hors ligne Membre Points: 35 Défis: 0 Message

Citer : Posté le 17/12/2023 16:00 | #


Lephenixnoir a écrit :
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.

LienAjouter une imageAjouter une vidéoAjouter un lien vers un profilAjouter du codeCiterAjouter un spoiler(texte affichable/masquable par un clic)Ajouter une barre de progressionItaliqueGrasSoulignéAfficher du texte barréCentréJustifiéPlus petitPlus grandPlus de smileys !
Cliquez pour épingler Cliquez pour détacher Cliquez pour fermer
Alignement de l'image: Redimensionnement de l'image (en pixel):
Afficher la liste des membres
:bow: :cool: :good: :love: ^^
:omg: :fusil: :aie: :argh: :mdr:
:boulet2: :thx: :champ: :whistle: :bounce:
valider
 :)  ;)  :D  :p
 :lol:  8)  :(  :@
 0_0  :oops:  :grr:  :E
 :O  :sry:  :mmm:  :waza:
 :'(  :here:  ^^  >:)

Σ π θ ± α β γ δ Δ σ λ
Veuillez donner la réponse en chiffre
Vous devez activer le Javascript dans votre navigateur pour pouvoir valider ce formulaire.

Si vous n'avez pas volontairement désactivé cette fonctionnalité de votre navigateur, il s'agit probablement d'un bug : contactez l'équipe de Planète Casio.

Planète Casio v4.3 © créé par Neuronix et Muelsaco 2004 - 2024 | Il y a 54 connectés | Nous contacter | Qui sommes-nous ? | Licences et remerciements

Planète Casio est un site communautaire non affilié à Casio. Toute reproduction de Planète Casio, même partielle, est interdite.
Les programmes et autres publications présentes sur Planète Casio restent la propriété de leurs auteurs et peuvent être soumis à des licences ou copyrights.
CASIO est une marque déposée par CASIO Computer Co., Ltd