Mukmin039

strtok

May 24th, 2022 (edited)
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.92 KB | None | 0 0
  1. /*
  2.  * File:   Sandbox.c
  3.  * Author: Rito
  4.  *
  5.  * Created on 24 de mayo de 2022, 12:34
  6.  */
  7.  
  8.  
  9. #include <xc.h>
  10. #include <string.h>
  11. #include <stdio.h>
  12. #include <math.h>
  13.  
  14.  
  15.  
  16. unsigned char bufferRX[50];
  17. unsigned char bufferTX[50];
  18. unsigned char data[50];
  19. unsigned char host[50];
  20. char dispositivo[3];
  21. char genero[3];
  22. int age;
  23. char edo_civil[3];
  24. char hijos[3];
  25. char religion [3];
  26. char educacion[3];
  27. char toma[3];
  28. char fuma[3];
  29. char ocupacion[3];
  30. char caracter[3];
  31. char casa[3];
  32. char carro[3];
  33. char comportamiento[3];
  34.  
  35. char dispositivo_h[3];
  36. char genero_h[3];
  37. int age_h;
  38. char edo_civil_h[3];
  39. char hijos_h[3];
  40. char religion_h [3];
  41. char educacion_h[3];
  42. char toma_h[3];
  43. char fuma_h[3];
  44. char ocupacion_h[3];
  45. char caracter_h[3];
  46. char casa_h[3];
  47. char carro_h[3];
  48. char comportamiento_h[3];
  49.  
  50. void main(void) {
  51.  
  52. sprintf((char*)bufferTX,"45,65,43,69,6B,6F,75,7F,81,83,8B,8E,90,96");
  53. sprintf((char*)bufferRX,"29 66 42 67 6C 6F 9B 7F 81 82 88 9B 9B 92");
  54.  
  55. strcpy (data, bufferTX);
  56. strcpy(host, bufferRX);
  57. char d[3]={0x20,0xD,NULL,","};
  58. char *datap0 = strtok(data,d);
  59. strcpy(dispositivo ,datap0); // add the gender
  60. *datap0=strtok(NULL,d);
  61. strcpy(genero,*datap0); // add the gender
  62. *datap0=strtok(NULL,d);
  63. age= atoi(datap0);  //add the age and converted into integer
  64. *datap0=strtok(NULL,d);
  65. strcpy(edo_civil,datap0);//if married or not
  66. *datap0=strtok(NULL,d);
  67. strcpy(hijos,datap0);//if any kids
  68. *datap0=strtok(NULL,d);
  69. strcpy(religion,datap0); // religion
  70. *datap0=strtok(NULL,d);
  71. strcpy(educacion ,datap0);//education
  72. *datap0=strtok(NULL,d);
  73. strcpy(toma ,datap0);//drinks
  74. *datap0=strtok(NULL,d);
  75. strcpy(fuma ,datap0);//smokes
  76. *datap0=strtok(NULL,d);
  77. strcpy(ocupacion ,datap0); //occupation
  78. *datap0=strtok(NULL,d);
  79. strcpy(caracter ,datap0);//character
  80. *datap0=strtok(NULL,d);
  81. strcpy(casa ,datap0);//house
  82. *datap0=strtok(NULL,d);
  83. strcpy(carro ,datap0);//car
  84. *datap0=strtok(NULL,d);
  85. strcpy(comportamiento,datap0);
  86. *datap0=strtok(NULL,d);
  87.  
  88.  //en el host
  89.  
  90.  
  91. *datap0 = strtok(host,d);
  92. strcpy(dispositivo_h,datap0);//add the device into the string
  93. *datap0=strtok(NULL,d);
  94. strcpy(genero_h,datap0); // add the gender
  95. *datap0=strtok(NULL,d);
  96. age_h= atoi(datap0);  //add the age and converted into integer
  97. *datap0=strtok(NULL,d);
  98. strcpy(edo_civil_h,datap0);//if married or not
  99. *datap0=strtok(NULL,d);
  100. strcpy(hijos_h,datap0);//if any kids
  101. *datap0=strtok(NULL,d);
  102. strcpy(religion_h,datap0); // religion
  103. *datap0=strtok(NULL,d);
  104. strcpy(educacion_h ,datap0);//education
  105. *datap0=strtok(NULL,d);
  106. strcpy(toma_h ,datap0);//drinks
  107. *datap0=strtok(NULL,d);
  108. strcpy(fuma_h ,datap0);//smokes
  109. *datap0=strtok(NULL,d);
  110. strcpy(ocupacion_h ,datap0); //occupation
  111. *datap0=strtok(NULL,d);
  112. strcpy(caracter_h ,datap0);//character
  113. *datap0=strtok(NULL,d);
  114. strcpy(casa_h ,datap0);//house
  115. *datap0=strtok(NULL,d);
  116. strcpy(carro_h ,datap0);//car
  117. *datap0=strtok(NULL,d);
  118. strcpy(comportamiento_h,datap0);
  119. *datap0=strtok(NULL,d);
  120.  
  121. }
  122.  
  123.  
  124.  
Add Comment
Please, Sign In to add comment