New C projects
This commit is contained in:
parent
8461050310
commit
f1660b1be3
5 changed files with 559 additions and 0 deletions
164
csvfc.c
Normal file
164
csvfc.c
Normal file
|
@ -0,0 +1,164 @@
|
|||
/*****************************************\
|
||||
|* Code C pour lire un fichier CSV. *|
|
||||
|* *|
|
||||
|* Auteur : Frederic Henry. *|
|
||||
|* Note : On peut surement faire mieux ! *|
|
||||
\*****************************************/
|
||||
/*g++ -Wall -Wextra -c csvfc.c && g++ -Wall -Wextra csvfc.o -o csvfc && ./csvfc;*/
|
||||
/* Bibliotheques standards de C 90. */
|
||||
/* Entree/sortie & fichiers. */
|
||||
#include <stdio.h>
|
||||
/* Caracteres. */
|
||||
#include <string.h>
|
||||
/* Controles de procedures. */
|
||||
#include <stdlib.h>
|
||||
/* Lignes. */
|
||||
#define LINES 8
|
||||
/* Colonnes. */
|
||||
#define ROWS 6
|
||||
/* Fonction secondaire. */
|
||||
/* Un texte d'aide pour connaître les commandes. */
|
||||
/* Une seule commande ici : '-h' pour l'aide. X-) */
|
||||
void helper(void)/* Que du texte... :-| */
|
||||
{
|
||||
printf("/*********************************************\\\n");
|
||||
printf("|* Section d'aide pour le programme 'csvfc'. *|\n");
|
||||
printf("|* *|\n");
|
||||
printf("|* csvfc [-h|--help] *|\n");
|
||||
printf("|* *|\n");
|
||||
printf("\\*********************************************/\n");
|
||||
printf("Pour manipuler ce programme, il suffit d'avoir");
|
||||
printf(" le fichier 'csvin.csv' dans le meme repertoire.\n\n");
|
||||
printf(" Contenu de 'csvin.csv' :\n");
|
||||
printf("\"X\",\"Y\",\"Z\",\"U\",\"V\",\"P\"\n");
|
||||
printf("1,1,1,1,1,1\n");
|
||||
printf("2,2,2,2,2,2\n");
|
||||
printf("3,3,3,3,3,3\n");
|
||||
printf("4,4,4,4,4,4\n");
|
||||
printf("5,5,5,5,5,5\n");
|
||||
printf("6,6,6,6,6,6\n");
|
||||
printf("7,7,7,7,7,7\n");
|
||||
printf("8,8,8,8,8,8\n\n");
|
||||
printf("Apres ca, on execute 'csvf'.\n");
|
||||
}
|
||||
/* Fonction principale. */
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
/* Avant de commencer, a-t-on ajoute une option ? */
|
||||
if (argc == 2)/* Si une option... */
|
||||
{
|
||||
/* En cas d'option '-h' ou '--help'... */
|
||||
if (strcmp(argv[1],"--help")==0 || strcmp(argv[1],"-h")==0)
|
||||
{
|
||||
/* Page d'aide invoquee. */
|
||||
helper();
|
||||
/* Fin du programme avec succes. */
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
}
|
||||
/* Texte memorise. */
|
||||
char text[LINES+1][5*ROWS-1];
|
||||
/* Indices ligne/colonne. */
|
||||
char i,j;
|
||||
/* Matrice d'entiers. */
|
||||
int matrix[LINES][ROWS];
|
||||
/* Pour s'assurer la fin de chaque ligne.
|
||||
* Une ligne = une sous-chaine.
|
||||
*/
|
||||
for (i=1; i<ROWS; i=i+1)
|
||||
{
|
||||
text[i][5*ROWS-1-1]='\0';
|
||||
}
|
||||
/* Pour la deco. car j'aime ca. :-D */
|
||||
printf("/*****************************************\\\n");
|
||||
printf("|* Code C++ pour lire un fichier CSV. *|\n");
|
||||
printf("|* *|\n");
|
||||
printf("|* Auteur : Frederic Henry. *|\n");
|
||||
printf("|* Note : On peut surement faire mieux ! *|\n");
|
||||
printf("\\*****************************************/\n\n");
|
||||
printf("Lecture de \"./csvin.csv\"...\n");
|
||||
/* Lecture de fichier texte avec "FILE*". */
|
||||
FILE* entree;
|
||||
entree = fopen("./csvin.csv","r");
|
||||
printf("Table CSV (en-tete) :\n");
|
||||
/* Ligne 0 lue. */
|
||||
fscanf(entree,"%s",text[0]);
|
||||
printf("%s\n",text[0]);
|
||||
/* Les autres lignes. */
|
||||
printf("Table CSV (corps) :\n");
|
||||
for (i=1; i<LINES+1; i=i+1)
|
||||
{
|
||||
fscanf(entree,"%s",text[i]);
|
||||
printf("%s\n",text[i]);
|
||||
}
|
||||
/* Lecture integrale. */
|
||||
printf("Table CSV (tout) :\n");
|
||||
for (i=0; i<LINES+1; i=i+1)
|
||||
{
|
||||
printf("%s\n",text[i]);
|
||||
}
|
||||
printf("\n");
|
||||
/* Fermeture du fichier. */
|
||||
fclose(entree);
|
||||
/* Affichage du tableau de caracteres. */
|
||||
printf("Version tableau de caracteres :\n");
|
||||
/* En-tete. */
|
||||
for (j=0; j<ROWS; j=j+1)
|
||||
{
|
||||
printf("%c ",text[0][4*j+1]);
|
||||
}
|
||||
/* Corps. */
|
||||
printf("\n");
|
||||
for (i=1; i<LINES+1; i=i+1)
|
||||
{
|
||||
for (j=0; j<ROWS; j=j+1)
|
||||
{
|
||||
printf("%c ",text[i][2*j]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
printf("\n");
|
||||
/* Pareil, facon nombres entiers. */
|
||||
printf("Version tableau d'entiers :\n");
|
||||
/* Conversion du texte a la matrice entiere. */
|
||||
for (i=0; i<LINES; i=i+1)
|
||||
{
|
||||
for (j=0; j<ROWS; j=j+1)
|
||||
{
|
||||
matrix[i][j]=(int)text[i+1][2*j]-48;
|
||||
}
|
||||
}
|
||||
/* Affichage de la matrice. */
|
||||
for (i=0; i<LINES; i=i+1)
|
||||
{
|
||||
for (j=0; j<ROWS; j=j+1)
|
||||
{
|
||||
printf("%d ",matrix[i][j]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
printf("\n");
|
||||
/* Ce coup-ci, ecriture de tableau dans un fichier. */
|
||||
printf("Ecriture d'un tableau CSV \"./csvout.csv\"...\n");
|
||||
FILE* sortie;
|
||||
sortie = fopen("csvout.csv","w");
|
||||
/* Dabord l'en-tete. */
|
||||
fprintf(sortie,"\"X\",\"Y\",\"Z\",\"U\",\"V\",\"P\"\n");
|
||||
/* En suite le corps. */
|
||||
for (i=0; i<LINES; i=i+1)
|
||||
{
|
||||
for (j=0; j<ROWS-1; j=j+1)
|
||||
{
|
||||
fprintf(sortie,"%d,",matrix[i][j]);
|
||||
}
|
||||
fprintf(sortie,"%d\n",matrix[i][ROWS-1]);
|
||||
}
|
||||
/* Fichier ferme. */
|
||||
fclose(sortie);
|
||||
printf("\n");
|
||||
/* Fini. */
|
||||
printf("Fin\n");
|
||||
/* Pour dire que tout a bien marche. */
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
66
invNb.c
Normal file
66
invNb.c
Normal file
|
@ -0,0 +1,66 @@
|
|||
/*********************\
|
||||
|**Frédéric Henry*****|
|
||||
|**SETSIS 2020********|
|
||||
\*********************/
|
||||
/* gcc -Wall -Wextra -o invNb invNb.c */
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
/* Opérateur puissance. */
|
||||
int puis(int nb, int i)
|
||||
{
|
||||
/* Base. */
|
||||
int b=nb;
|
||||
/* Multiplications. */
|
||||
if(i!=0)
|
||||
{
|
||||
for(long int j=0; j<i-1; j=j+1)
|
||||
{
|
||||
nb=nb*b;
|
||||
}
|
||||
return nb;
|
||||
}
|
||||
/* Extension nulle. */
|
||||
else
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
/* Fonction principale. */
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
/* Aide. */
|
||||
if(!strcmp(argv[1],"-h")||!strcmp(argv[1],"--help"))
|
||||
{
|
||||
printf("Usage : %s -h|--help|NUMBER\n",argv[0]);
|
||||
printf("Litteral inverse of NUMBER is returned.\n");
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
/* Le nombre entier non signé en entrée. */
|
||||
else
|
||||
{
|
||||
/* Nombre de chiffres. */
|
||||
const long int taille = strlen(argv[1]);
|
||||
/* Vraiment un nombre entier non signé?
|
||||
* Dans ce cas, les caractères sont dans
|
||||
* [48;57].
|
||||
*/
|
||||
for(long int i=0; i<taille; i=i+1)
|
||||
{
|
||||
if(argv[1][i]<48||argv[1][i]>57)
|
||||
{
|
||||
/* Si non, erreur! */
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
/* Nombre littéralement inversé. */
|
||||
int nb=0;
|
||||
for(long int i=0; i<taille; i=i+1)
|
||||
{
|
||||
nb=nb+(int)(argv[1][taille-i-1]-48)*puis(10,taille-i-1);
|
||||
}
|
||||
/* Nombre inversé en sortie. */
|
||||
printf("%d\n", nb);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
}
|
95
random.c
Normal file
95
random.c
Normal file
|
@ -0,0 +1,95 @@
|
|||
/*
|
||||
* Fichier : random.c
|
||||
* Auteur : Frédéric Henry
|
||||
* Diplôme : Lpro Vision robotique
|
||||
* Date : 23/10/2018
|
||||
* Version : 0.1
|
||||
*/
|
||||
/* En-tête : Bibliothèque standard pour I/O. */
|
||||
#include <stdio.h>
|
||||
/* En-tête : Bibliothèque standard pour "rand()" et "random()". */
|
||||
#include <stdlib.h>
|
||||
/* Taille du tableau. */
|
||||
#define N 128
|
||||
/* Valeur aléatoire maximale. */
|
||||
#define MAXI 2147483648
|
||||
/* Fonction principale.
|
||||
* Un programme pour étudier la fonction "random()",
|
||||
* la distribution uniforme et celle normale.
|
||||
*/
|
||||
int main(void)
|
||||
{
|
||||
unsigned i ;
|
||||
unsigned j ;
|
||||
short int flag0 = 0 ;
|
||||
short int flag1 = 1 ;
|
||||
long int maximum = 0 ;
|
||||
long int minimum = MAXI ;
|
||||
long int alea ;
|
||||
unsigned table[N] ;
|
||||
/* Remplissage de zéros. */
|
||||
for (i=0;i<N;i=i+1)
|
||||
{
|
||||
table[i] = 0 ;
|
||||
}
|
||||
printf("Randomness values :\n") ;
|
||||
for(i=0;i<10000;i=i+1)
|
||||
{
|
||||
/* Création de valeur aléatoire. */
|
||||
alea = 0 ;
|
||||
for (j=0;j<16;j=j+1)
|
||||
{
|
||||
/* diviser atténue l'amplitude. */
|
||||
alea = random()/16 + alea ;
|
||||
}
|
||||
/* Classement croissant des valeurs. */
|
||||
for (j=0;j<N;j=j+1)
|
||||
{
|
||||
/* Multiplier élargit les intervalles. */
|
||||
if (alea > MAXI / N * j && alea < MAXI / N * (j+1))
|
||||
{
|
||||
table[j] = table[j] + 1 ;
|
||||
j = N ;
|
||||
}
|
||||
}
|
||||
/* Recherche des extremums. */
|
||||
if (maximum < alea)
|
||||
{
|
||||
maximum = alea ;
|
||||
}
|
||||
if (minimum > alea)
|
||||
{
|
||||
minimum = alea ;
|
||||
}
|
||||
/* printf("N%02u = %010ld\n", i, alea) ; */
|
||||
}
|
||||
printf("Highest number : %ld\n", minimum) ;
|
||||
printf("Highest number : %ld\n", maximum) ;
|
||||
/* Multiples binaires. */
|
||||
alea = 1 ;
|
||||
i = 0 ;
|
||||
while (alea < maximum)
|
||||
{
|
||||
alea = alea * 2 ;
|
||||
i = i + 1 ;
|
||||
if (alea > minimum && flag1 == 1)
|
||||
{
|
||||
printf("2^%2u = %ld\n", i, alea) ;
|
||||
flag1 = 0 ;
|
||||
}
|
||||
}
|
||||
printf("2^%2u = %ld\n", i, alea) ;
|
||||
/* Graphe */
|
||||
printf("Graph :\n\n") ;
|
||||
for (i=0;i<N;i=i+1)
|
||||
{
|
||||
printf("[ %03u / %03d ]\t", i+1, N) ;
|
||||
/* Sauter des valeurs atténue l'amplitude. */
|
||||
for (j=0;j<table[i];j=j+2)
|
||||
{
|
||||
printf("|") ;
|
||||
}
|
||||
printf("\n") ;
|
||||
}
|
||||
return 0 ;
|
||||
}
|
120
sapin.c
Normal file
120
sapin.c
Normal file
|
@ -0,0 +1,120 @@
|
|||
/**************************************\
|
||||
| Alnotz |
|
||||
| Le générateur de sapin |
|
||||
\**************************************/
|
||||
/* gcc -Wall -Wextra -o sapin sapin.c */
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
/* Une entrée numérique? */
|
||||
int estNumerique(char chaine[])
|
||||
{
|
||||
size_t taille = strlen(chaine);
|
||||
for(size_t i=0; i<taille; i=i+1)
|
||||
{
|
||||
switch(chaine[i])
|
||||
{
|
||||
case '0':
|
||||
case '1':
|
||||
case '2':
|
||||
case '3':
|
||||
case '4':
|
||||
case '5':
|
||||
case '6':
|
||||
case '7':
|
||||
case '8':
|
||||
case '9':
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
/* Bloc d'espaces ou traits */
|
||||
void multibloc(unsigned long int compteur,unsigned int no)
|
||||
{
|
||||
if(no==0)
|
||||
{
|
||||
for(unsigned long int i=compteur; i>0; i=i-1)
|
||||
{
|
||||
printf(" ");
|
||||
}
|
||||
}
|
||||
if(no==1)
|
||||
{
|
||||
for(unsigned long int i=compteur; i>0; i=i-1)
|
||||
{
|
||||
printf("____");
|
||||
}
|
||||
}
|
||||
}
|
||||
/* Fonction principale */
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
if(argc<2)
|
||||
{
|
||||
printf("Pas d'argument? Ça sent le sapin!\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
/* Aide */
|
||||
if(!strcmp(argv[1],"-h")||!strcmp(argv[1],"--help"))
|
||||
{
|
||||
printf("Commande : ");
|
||||
printf("%s",argv[0]);
|
||||
printf(" -h | --help | NOMBRE\n");
|
||||
printf("-h | --help\t\tDonne l\'aide.\n");
|
||||
printf("NOMBRE\t\tConstruit l\'arbre sur NOMBRE étages.\n");
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
if(!estNumerique(argv[1]))
|
||||
{
|
||||
printf("Tape un nombre!\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
/* Texte => Nombre */
|
||||
unsigned long int hauteur = strtoul(argv[1],argv,10);
|
||||
/* Étoile du soir */
|
||||
multibloc(hauteur-1,0);
|
||||
printf(" __/\\__\n");
|
||||
multibloc(hauteur-1,0);
|
||||
printf(" \\ /\n");
|
||||
multibloc(hauteur-1,0);
|
||||
printf(" \\/\\/\n");
|
||||
multibloc(hauteur-1,0);
|
||||
printf("____/ \\____\n");
|
||||
/* Étages */
|
||||
for(unsigned long int i=hauteur-1; i>0; i=i-1)
|
||||
{
|
||||
/* Ligne 0 */
|
||||
multibloc(i,0);
|
||||
printf("\\ ");
|
||||
multibloc(2*(hauteur-i),0);
|
||||
printf(" /\n");
|
||||
/* Ligne 1 */
|
||||
multibloc(i-1,0);
|
||||
multibloc(1,1);
|
||||
printf("_\\");
|
||||
multibloc(2*(hauteur-i),0);
|
||||
printf("/_");
|
||||
multibloc(1,1);
|
||||
printf("\n");
|
||||
}
|
||||
/* Dernier étage. */
|
||||
printf("\\ ");
|
||||
multibloc(2*hauteur,0);
|
||||
printf(" /\n \\");
|
||||
multibloc(2*hauteur,1);
|
||||
printf("/ \n");
|
||||
/* Tronc */
|
||||
for(unsigned long int i=0; i<hauteur; i=i+1)
|
||||
{
|
||||
multibloc(hauteur,0);
|
||||
printf("| |\n");
|
||||
}
|
||||
/* Sol */
|
||||
multibloc(hauteur,0);
|
||||
printf("|__|\n");
|
||||
/* FINI! */
|
||||
return EXIT_SUCCESS;
|
||||
}
|
114
wcplus.c
Normal file
114
wcplus.c
Normal file
|
@ -0,0 +1,114 @@
|
|||
/*********************\
|
||||
| WCPlus |
|
||||
| By Alnotz |
|
||||
\*********************/
|
||||
/*
|
||||
gcc -fPIC -Wall -Wextra -o wcplus.o `/usr/bin/pkg-config --libs --cflags weechat` -c wcplus.c
|
||||
gcc -shared -fPIC -Wall -Wextra -o wcplus.so wcplus.o
|
||||
*/
|
||||
#include <stdlib.h>
|
||||
#include <weechat-plugin.h>
|
||||
#define VERBOSE_MASKS_SIZE 3
|
||||
#define HELP_MASKS_SIZE 3
|
||||
struct t_weechat_plugin *weechat_plugin = NULL;
|
||||
WEECHAT_PLUGIN_NAME("WCPlus");
|
||||
WEECHAT_PLUGIN_DESCRIPTION("Juste une autre extension");
|
||||
WEECHAT_PLUGIN_AUTHOR("Alnotz <alnotz@protonmail.com>");
|
||||
WEECHAT_PLUGIN_VERSION("0.2");
|
||||
WEECHAT_PLUGIN_LICENSE("GNU GPLv3");
|
||||
WEECHAT_PLUGIN_PRIORITY(999);
|
||||
void arg_test(int argc,
|
||||
char **argv)
|
||||
{
|
||||
weechat_printf(NULL, "%s###########%s", weechat_color("*green"), weechat_color("reset"));
|
||||
weechat_printf(NULL, "%sTotal d’arguments: %s%d%s", weechat_color("red"), weechat_color("*blue"), argc, weechat_color("reset"));
|
||||
for(int i=0; i<argc; i=i+1)
|
||||
{
|
||||
weechat_printf(NULL, "%sArgument n°%d: %s%s%s", weechat_color("red"), i, weechat_color("*blue"), argv[i], weechat_color("reset"));
|
||||
}
|
||||
weechat_printf(NULL, "%s###########%s", weechat_color("*green"), weechat_color("reset"));
|
||||
}
|
||||
int command_truc(const void *pointer,
|
||||
void *data,
|
||||
struct t_gui_buffer *buffer,
|
||||
int argc,
|
||||
char **argv,
|
||||
char **argv_eol)
|
||||
{
|
||||
(void) pointer;
|
||||
(void) data;
|
||||
(void) buffer;
|
||||
(void) argv_eol;
|
||||
if(argc == 1)
|
||||
{
|
||||
weechat_printf(NULL, "Tu peux taper `%s/truc -help%s`.", weechat_color("*white"), weechat_color("reset"));
|
||||
}
|
||||
else
|
||||
{
|
||||
unsigned char verbose_flag = 0;
|
||||
unsigned char help_flag = 0;
|
||||
for(int i=1; i<argc; i=i+1)
|
||||
{
|
||||
const char *verbose_masks[VERBOSE_MASKS_SIZE] = {"-v", "-verbose", NULL};
|
||||
const char *help_masks[HELP_MASKS_SIZE] = {"-h", "-help", NULL};
|
||||
if(weechat_string_match_list(argv[i], verbose_masks, 1) && verbose_flag == 0)
|
||||
{
|
||||
verbose_flag = 1;
|
||||
}
|
||||
if(weechat_string_match_list(argv[i], help_masks, 1) && help_flag == 0)
|
||||
{
|
||||
help_flag = 1;
|
||||
}
|
||||
}
|
||||
if(verbose_flag == 1)
|
||||
{
|
||||
arg_test(argc, argv);
|
||||
}
|
||||
if(help_flag == 1)
|
||||
{
|
||||
weechat_printf(NULL, "Maintenant tu peux taper `%s/help truc%s`.\n:-P", weechat_color("*white"), weechat_color("reset"));
|
||||
}
|
||||
}
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
int command_truc_options(const void *pointer,
|
||||
void *data,
|
||||
const char *completion_item,
|
||||
struct t_gui_buffer *buffer,
|
||||
struct t_gui_completion *completion)
|
||||
{
|
||||
(void) pointer;
|
||||
(void) data;
|
||||
(void) completion_item;
|
||||
(void) buffer;
|
||||
weechat_completion_list_add (completion, "-verbose", 0, WEECHAT_LIST_POS_END);
|
||||
weechat_completion_list_add (completion, "-help", 0, WEECHAT_LIST_POS_END);
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
int weechat_plugin_init (struct t_weechat_plugin *plugin,
|
||||
int argc, char *argv[])
|
||||
{
|
||||
weechat_plugin = plugin;
|
||||
weechat_hook_completion("truc_options",
|
||||
"Complétion des options de `truc`",
|
||||
&command_truc_options,
|
||||
NULL,
|
||||
NULL);
|
||||
weechat_hook_command("truc",
|
||||
"C’est une commande d'essai.",
|
||||
"[-v|-verbose] [-h|-help]",
|
||||
"-h|-help : Aide\n"
|
||||
"-v|-verbose : Débogage",
|
||||
"%(truc_options) %(truc_options)",
|
||||
&command_truc,
|
||||
NULL,
|
||||
NULL);
|
||||
weechat_printf(NULL, "%sExtension chargée!%s", weechat_color("*red"), weechat_color("reset"));
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
int weechat_plugin_end (struct t_weechat_plugin *plugin)
|
||||
{
|
||||
(void) plugin;
|
||||
weechat_printf(NULL, "%sExtension dé-chargée!%s", weechat_color("*red"), weechat_color("reset"));
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
Loading…
Reference in a new issue