Skip to content
Snippets Groups Projects
Commit ee7c5ba9 authored by nathan accart's avatar nathan accart
Browse files

ajout TP03

parent 8c37003e
Branches
No related tags found
No related merge requests found
TP03/Exo1 0 → 100755
File added
#include <stdio.h>
#include <stdlib.h>
char * nouveau_tableau (int taille);
void initialise_tableau (char * tableau, int taille, char car);
void affiche_tableau (char * tableau, int taille);
void liberation_du_tableau (char * tableau);
void place_dans_tableau (char * tableau, int taille, int indice, char car);
char lecture_du_tableau (char * tableau, int taille, int indice);
int main(void){
char* tab = nouveau_tableau (4);
initialise_tableau (tab,4,'a');
affiche_tableau (tab,4);
//liberation_du_tableau (tab);
//affiche_tableau (tab,4);
place_dans_tableau (tab,4,2,'z');
affiche_tableau (tab,4);
lecture_du_tableau (tab, 4, 21);
}
char * nouveau_tableau (int taille){
char* pt;
pt = malloc(taille*sizeof(char));
return pt;
}
void initialise_tableau (char * tableau, int taille, char car){
for(int i = 0; i < taille; i++){
tableau[i] = 'a'+ i;
}
tableau[2] = 'e';
}
void affiche_tableau (char * tableau, int taille){
printf("\n");
for(int i = 0; i < taille; i++){
printf(" %c",tableau[i]);
}
printf("\n\n");
}
void liberation_du_tableau (char * tableau){
free(tableau);
printf("Le tablo conti1%c", *tableau);
}
void place_dans_tableau (char * tableau, int taille, int indice, char car){
tableau[indice] = car;
if(indice > taille || indice < taille){
printf("Erreur...Erreur...Erreur");
}
}
char lecture_du_tableau (char * tableau, int taille, int indice){
char car;
if(indice > taille || indice < 0){
tableau[indice] = '\0';
printf("Erreur...Erreur...Erreur");
car = '\0';
}else{
car = tableau[indice];
printf("Char : %c", car);
}
return car;
}
\ No newline at end of file
TP03/Exo2 0 → 100755
File added
#include <stdio.h>
#include <stdlib.h>
void initialiser_tableau(char* tab,int taille);
void affiche_tableau (char * tableau, int taille);
typedef struct {
char * tableau;
int taille;
} super_tableau_t;
int main(void){
super_tableau_t* super_tab = malloc(sizeof(super_tableau_t));
super_tab->taille = 4;
super_tab->tableau = malloc(super_tab->taille * sizeof(char));
initialiser_tableau(super_tab->tableau,super_tab->taille);
affiche_tableau (super_tab->tableau,super_tab->taille);
}
void initialiser_tableau(char* tab,int taille){
tab[0] = 'a';
for(int i = 0; i < taille; i++){
tab[i] = tab[0] + i;
}
}
void affiche_tableau (char * tableau, int taille){
printf("\n");
for(int i = 0; i < taille; i++){
printf(" %c",tableau[i]);
}
printf("\n\n");
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment