Convertir Markdown a Markup
Résolu
keterson
Messages postés
9
Statut
Membre
-
keterson Messages postés 9 Statut Membre -
keterson Messages postés 9 Statut Membre -
Salut à tous et à toutes.
Quelqu-un pourrait-il m-aider .
Comment pourrait-on en langage C creer un outil qui prend des archives de texte plat (markdown) et il le change en archives html (markup).
Merci d-avance
--
Peace & love
Quelqu-un pourrait-il m-aider .
Comment pourrait-on en langage C creer un outil qui prend des archives de texte plat (markdown) et il le change en archives html (markup).
Merci d-avance
--
Peace & love
3 réponses
-
Grosso modo ca consiste juste à ouvrir en écriture un fichier html (fopen), écrire
<html> <body>
Ensuite tu ouvre en lecture le fichier txt en lecture (fopen) que tu lis ligne par ligne avec un getline par exemple. Tu écris la ligne en question dans le fichier html avec un fprintf, et tu rajoute à la fin de la ligne recopiée un<br>
Tu fermes le fichier txt (fclose), et tu écris dans le fichier html :</body> </html>
Tu fermes le fichier html (fclose) et c'est fini.
Si ce n'est pas la réponse que tu attendais précise au travers d'un exemple ce que tu veux faire.
Bonne chance -
(mando@aldur) (~) $ cat plop.txt blabla blabla blibli blibli blublu blublu bloblo bloblo (mando@aldur) (~) $ cat plop.c #include <stdio.h> #include <stdlib.h> int main(){ const char *filename_txt = "plop.txt"; const char *filename_html = "plop.html"; FILE *f_html = fopen(filename_html,"w"); // Ecrire l'entete html fprintf(f_html,"<html><body>\n"); // Reporter le text { char * line = NULL; size_t len = 0; FILE * f_txt = fopen(filename_txt,"r"); while (getline(&line, &len, f_txt) != -1) { fprintf(f_html,"%s<br>\n",line); } fclose(f_txt); } // Ecrire le pied de page html fprintf(f_html,"</body></html>\n"); fclose(f_html); return EXIT_SUCCESS; } (mando@aldur) (~) $ gcc -W -Wall plop.c plop.c: In function ‘main’: plop.c:17: warning: implicit declaration of function ‘getline’ (mando@aldur) (~) $ cat plop.html <html><body> blabla blabla <br> blibli blibli <br> blublu blublu <br> bloblo bloblo <br> </body></html>
Bonne chance -
Merci beaucoup mon ami .
Ca marche maintenant.Mais la seule chose c'est que le programme ne voulait pas compiler dans Dev-Cpp , sinon que gcc.
(mando@aldur) (~) $ cat plop.txt
blabla blabla
blibli blibli
blublu blublu
bloblo bloblo
(mando@aldur) (~) $ cat plop.c
#include <stdio.h>
#include <stdlib.h>
int main(){
const char *filename_txt = "plop.txt";
const char *filename_html = "plop.html";
FILE *f_html = fopen(filename_html,"w");
// Ecrire l'entete html
fprintf(f_html,"<html><body>\n");
// Reporter le text
{
char * line = NULL;
size_t len = 0;
FILE * f_txt = fopen(filename_txt,"r");
while (getline(&line, &len, f_txt) != -1) {
fprintf(f_html,"%s<br>\n",line);
}
fclose(f_txt);
}
// Ecrire le pied de page html
fprintf(f_html,"</body></html>\n");
fclose(f_html);
return EXIT_SUCCESS;
}
(mando@aldur) (~) $ gcc -W -Wall plop.c
plop.c: In function ‘main’:
plop.c:17: warning: implicit declaration of function ‘getline’
(mando@aldur) (~) $ cat plop.html
<html><body>
blabla blabla
<br>
blibli blibli
<br>
blublu blublu
<br>
bloblo bloblo
<br>
</body></html>