Advertisement
Guest User

Untitled

a guest
Jan 21st, 2019
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.36 KB | None | 0 0
  1. /*
  2. #include <stdio.h>
  3. #include "functions.h"
  4. int main() {
  5. Item* start = NULL;
  6. for (int i = 0; i < 5; i++) {
  7. addFirstItem(&start, i + 5);
  8. }
  9.  
  10. showItems(start, 5);
  11. //int x = 0;
  12. //int x = searchItem(start, 7);
  13. Item* tmp = searchItem(start, 7);
  14. if (tmp != NULL)
  15. printf("\nThe value %d has been found.\n", tmp->value);
  16.  
  17. if (removeAllItems(start) == 1)
  18. printf("All elements in list have been removed.\n");
  19. return 0;
  20. }*/
  21.  
  22. #include <stdio.h>
  23. #include <stdlib.h>
  24.  
  25. typedef struct Muscle{
  26. int selected;
  27. char * label;
  28. struct Muscle * next;
  29. } Muscle;
  30.  
  31. Muscle * searchMuscle(Muscle * start,const char * search);
  32.  
  33. typedef struct Exercice{
  34. char * name;
  35. char * description;
  36. Muscle * muscleTest;
  37. struct Exercice * next;
  38. } Exercice;
  39.  
  40. int addExercice(Exercice ** start, Muscle * start2,char * name, char * description, char * muscle){
  41. Exercice * inter=NULL;
  42. inter=malloc(sizeof(Exercice));
  43. if(inter==NULL) return 0;
  44. inter->description=description;
  45. inter->name=name;
  46. inter->muscleTest=searchMuscle(start2,muscle);
  47.  
  48. printf(" name : %s ",name);
  49. printf(" description : %s \n",description);
  50. inter->next=*start;
  51. *start=inter;
  52. return 1 ;
  53. }
  54.  
  55. int addMuscle(Muscle ** start , int selected, char * label ){
  56. Muscle * inter;
  57. inter=malloc(sizeof(Muscle));
  58. if(inter==NULL) return 0;
  59. inter->selected=selected;
  60. inter->label=label;
  61. inter->next=*start;
  62. *start=inter;
  63. printf(" selected : %d ",selected);
  64. printf(" label : %s \n",label);
  65. return 1 ;
  66. }
  67.  
  68. Muscle * deleteMuscle(Muscle* start){
  69. if (start == NULL) return NULL;
  70. Muscle * tmp;
  71. tmp=start;
  72. free(start);
  73. return tmp;
  74. }
  75.  
  76. int showMuscle(Muscle* start, int n) {
  77. // Muscle* tmp = start;
  78. if (start == NULL) return 0;
  79.  
  80. if(n==0) {
  81. while(start->next!=NULL) {
  82. if(start->selected==1){
  83. printf("%s \n", start->label);
  84. }
  85. start = start->next;
  86.  
  87. }
  88. }else{
  89. while(n>0){
  90. if(start->selected==1){
  91. printf("%s \n", start->label);
  92. }
  93. start = start->next;
  94. n--;
  95. }
  96. }
  97. return 1;
  98. }
  99.  
  100. int showExo(Exercice* start, int n) {
  101. // Muscle* tmp = start;
  102. if (start == NULL) return 0;
  103.  
  104. if(n==-1) {
  105. do{
  106. if(start->muscleTest->selected==1){
  107. printf("%s : ", start->name);
  108. printf("%s \n", start->muscleTest->label);
  109. }
  110. start = start->next;
  111. }while(start!=NULL) ;
  112. }else{
  113. while(n>0){
  114. // if(start->selected==1){
  115. printf("%s : ", start->name);
  116. printf("%s \n", start->muscleTest->label);
  117. // }
  118. start = start->next;
  119. n--;
  120. }
  121. }
  122. return 1;
  123. }
  124.  
  125. void function(void){
  126. printf("pute");
  127. }
  128.  
  129. Muscle * searchMuscle(Muscle * start,const char * search){
  130. while(start!=NULL){
  131. if( start->label==search){
  132. return start;
  133. }
  134. start=start->next;
  135. }
  136. return NULL;
  137. }
  138.  
  139.  
  140. void function2(int x, int y ,char * titre, void (*nomdelafonction)(void)){
  141. printf("%d",x);
  142. printf("%d",y);
  143. printf("%s",titre);
  144.  
  145. }
  146. int main(int argc, char ** argv){
  147.  
  148.  
  149. Muscle * start=NULL;
  150. addMuscle(&start,1, "jambe" );
  151. addMuscle(&start,1, "dos" );
  152. addMuscle(&start,0, "pec" );
  153. addMuscle(&start,1, "epaule" );
  154. addMuscle(&start,1, "bras" );
  155. Exercice * start2=NULL;
  156. addExercice(&start2,start,"a","aDef","jambe");
  157. addExercice(&start2,start,"b","bDef","dos");
  158. addExercice(&start2,start,"c","cDef","pec");
  159. addExercice(&start2,start,"d","dDef","epaule");
  160. addExercice(&start2,start,"e","eDef","bras");
  161.  
  162. showExo (start2, -1);
  163. /*
  164. printf("test123 : %d", start2->muscleTest);
  165. printf("test123 : %s", start2->name);
  166. printf("test123 : %s", start2->description);
  167.  
  168. /*
  169. addExercice(&start2,"developper couche", "allonge avec une barre",&start->bras );
  170. addExercice(&start2,"pompe", "au sol","bras" );
  171. showMuscle (start2, 0);
  172. */
  173.  
  174. /*
  175.  
  176. void (* pointeurSurFonction)(int, int, char *, void);
  177. pointeurSurFonction=function2;
  178. (*pointeurSurFonction)(1,2,"test",function);
  179.  
  180. */
  181.  
  182. return 0;
  183. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement