diff --git a/APL1.1/TP14/initiales.c b/APL1.1/TP14/initiales.c new file mode 100644 index 0000000..c2a8434 --- /dev/null +++ b/APL1.1/TP14/initiales.c @@ -0,0 +1,14 @@ +#include +#include +#include + +int main(int argc, char * argv[]) { + char initiales[15]; + + for (int i = 1; i < argc; i++) initiales[i-1] = argv[i][0]; + initiales[strlen(initiales)-1] = '\0'; + + printf("Initiales : %s\n", initiales); + return EXIT_SUCCESS; +} + diff --git a/APL1.1/TP14/lecture.c b/APL1.1/TP14/lecture.c new file mode 100644 index 0000000..bd80ffd --- /dev/null +++ b/APL1.1/TP14/lecture.c @@ -0,0 +1,24 @@ +#include +#include +#include + +int main(int argc, char * argv[]) { + char real_password[] = "test 1212 34"; + char password[27]; + + for (int i = 1; i < argc; i++) { + if (i != 1) strcat(password, " "); + if (strlen(password) + strlen(argv[i]) > 26) { + puts("Mot de passe trop long !"); + return EXIT_FAILURE; + } + strcat(password, argv[i]); + } + + if (strcmp(password, real_password)) { + puts("Authentification réussie."); + } else puts("Mot de passe incorrect."); + + return EXIT_SUCCESS; +} + diff --git a/APL1.1/TP14/miroir.c b/APL1.1/TP14/miroir.c new file mode 100644 index 0000000..54a48e0 --- /dev/null +++ b/APL1.1/TP14/miroir.c @@ -0,0 +1,17 @@ +#include +#include +#include + +int main(int argc, char * argv[]) { + char ligne_commande[200]; + for (int i = 0; i < argc; i++) { + if (i != 0) strcat(ligne_commande, " "); + strcat(ligne_commande, argv[i]); + } + ligne_commande[strlen(ligne_commande)] = '\0'; + + for (int i = strlen(ligne_commande); i >= 0; i--) printf("%c", ligne_commande[i]); + printf("\n"); + return EXIT_SUCCESS; +} + diff --git a/APL1.1/TP14/multiplication.c b/APL1.1/TP14/multiplication.c new file mode 100644 index 0000000..f2fa575 --- /dev/null +++ b/APL1.1/TP14/multiplication.c @@ -0,0 +1,34 @@ +#include +#include +#include + +int main(int argc, char * argv[]) { + long x, y; + char* position_x; + char* position_y; + + x = strtol(argv[1], &position_x, 10); + y = strtol(argv[2], &position_y, 10); + + if ((x == 0) && (position_x==argv[1])) { + puts("Entier invalide."); + return EXIT_FAILURE; + } else if (*position_x != '\0') { + puts("Conversion partielle !"); + return EXIT_FAILURE; + } + + if ((y == 0) && (position_y==argv[2])) { + puts("Entier invalide."); + return EXIT_FAILURE; + } else if (*position_y != '\0') { + puts("Conversion partielle !"); + return EXIT_FAILURE; + } + + long z = x * y; + printf("%d * %d = %d\n", x, y, z); + + return EXIT_SUCCESS; +} + diff --git a/APL1.1/TP14/statistiques.c b/APL1.1/TP14/statistiques.c new file mode 100644 index 0000000..408c525 --- /dev/null +++ b/APL1.1/TP14/statistiques.c @@ -0,0 +1,31 @@ +#include +#include +#include + +#define MAX_LEN 200 + +int main(int argc, char * argv[]) { + char str[MAX_LEN]; + + printf("Ligne de texte : "); + fgets(str, MAX_LEN, stdin); + + int e_found = 0; //Compte le nombre d'occurence de la lettre 'e'. + int letters_found[255] = {}; //Répertorie les différentes lettres trouvées. + int diff_letter_found = 0; //Compte le nombre de lettre différentes trouvées. + + for (int i = 0; i < strlen(str); i++) { + char letter = str[i]; + if (letter == 'e') e_found++; + + if (letters_found[letter+128] != 1) { + letters_found[letter+128] = 1; + diff_letter_found++; + } + } + + printf("La ligne contient %d e et %d lettre différente.\n", e_found, diff_letter_found); + + return EXIT_SUCCESS; +} + diff --git a/APL1.1/TP14/truandage.c b/APL1.1/TP14/truandage.c new file mode 100644 index 0000000..82b9a82 --- /dev/null +++ b/APL1.1/TP14/truandage.c @@ -0,0 +1,25 @@ +#include +#include +#include + +long long int textToLL(char* text) { + char new_text[200]; + + for (int i = strlen(text)-1; i >= 0; i--) { //La chaine doit être montée à l'envers + char new_letter[10]; + sprintf(new_letter, "%X", (int)text[i]); //Converti la lettre en sa valeur hexa + strcat(new_text, new_letter); //Rajoute à la suite de la séquence la lettre + } + + return strtoll(new_text, NULL, 16); //Converti la chaine en une valeur +} + + +int main(int argc, char * argv[]) { + long long int n = 32217268732456802LL; + long long int a = textToLL("bonsoir"); + printf("%s\n", &n); + printf("%s\n", &a); + return EXIT_SUCCESS; +} +