Advertisement
Guest User

VenturaLibrary.c

a guest
Jan 23rd, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.22 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include "VenturaLibrary.h"
  5.  
  6.  
  7. int disboy(char instruccionPal[20],int tiempoPal){
  8. int j = strlen(instruccionPal)-1;
  9. if(tiempoPal > 5){
  10.  
  11. for(int i=0; i<strlen(instruccionPal)/2;i++,j--)
  12. {
  13. if(*(instruccionPal+i)!= *(instruccionPal+j)){
  14. return 0;
  15.  
  16. }else{
  17. return 1;
  18. }
  19. }
  20. }
  21. else{
  22. return 0;
  23. }
  24. }
  25.  
  26. Ins* anadirInstruccion(Ins *head , char instruccion[20], int tiempo) //Ins *rootFromMain
  27. {
  28. if(head == NULL) //si no existe la lista, esto es, no hay memoria asignada, se crea el primer elemento 1 sola vez
  29. {
  30. head = (Ins *)malloc(sizeof(Ins));
  31. if(head == NULL) //opcional pero una buena práctica es preguntar si fue posible porque sí hubo memoria disponible
  32. {
  33. return NULL; // será la convención (en esta clase) de que no hubo éxito
  34. }
  35. strcpy(head->command,instruccion);
  36. head->tiempo = tiempo;
  37. head->Next = NULL;
  38. return head; // 1 será la convención (en esta clase) de que sí hubo éxito
  39. }
  40. else //si ya existe el head se estarán agregando (este código es el que se estará ejecutando la mayoría de las veces
  41. {
  42. Ins *temporal = (Ins *)malloc(sizeof(Ins));
  43. Ins *current = head;
  44. if(temporal == NULL) //opcional pero una buena práctica es preguntar si fue posible porque sí hubo memoria disponible
  45. {
  46. return NULL; // será la convención (en esta clase) de que no hubo éxito
  47. }
  48.  
  49. strcpy(temporal->command,instruccion);
  50. temporal->tiempo = tiempo;
  51. temporal->Next = NULL;
  52.  
  53. while(current->Next != NULL) //esto es para ir "caminando" y añadir al final el elemento
  54. {
  55. current=current->Next;
  56. }
  57. current->Next = temporal;
  58.  
  59. return head;
  60. }
  61.  
  62. }
  63. void recorrer (Ins* head)
  64. {
  65. Ins *temp = head;
  66. printf("Recorriendo...\n");
  67. while(temp) {
  68. printf("Nombre: %s\n", temp->command);
  69. printf("Tiempo: %d\n", temp->tiempo);
  70. temp = temp->Next ;
  71. }
  72. }
  73.  
  74. Ins* mandarInstrucciones(Ins *head) //en otras palabras, borrar
  75. {
  76. Ins *temp = head;
  77. printf("Recorriendo...\n");
  78. while(temp) {
  79. printf("Borrando{ Nombre: %s\n }\n", temp->command);
  80. head = temp->Next;
  81.  
  82. free(temp);
  83. temp = head;
  84. }
  85. return NULL;
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement