Advertisement
Guest User

Untitled

a guest
Feb 17th, 2020
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4.  
  5. char start_1[]="za"; //
  6. char choice_aa[]="aa"; //
  7. char choice_bb[]="bb"; //
  8. char choice_ab[]="ab"; //
  9. char choice_ba[]="ba"; //
  10.  
  11.  
  12. char start_2[]="za"; //
  13. char *user_imput; //
  14. char stop_1[]="az";
  15. char stop_2[]="bz";
  16. char binary[20]; //
  17. int exit_while = 1;
  18. int arr_position = 0;
  19.  
  20. int allocate(char *stringHelper, char *user_imput, int cont) {
  21. stringHelper[0] = *(user_imput+cont);
  22. cont++;
  23. stringHelper[1] = *(user_imput+cont);
  24. cont++;
  25.  
  26. return cont;
  27. }
  28.  
  29. int _allocate(char *strHelper, char* user_imput, int cont)
  30. {
  31.  
  32. }
  33.  
  34. int main(){
  35. user_imput = (char*)malloc(sizeof(char) * 1024);
  36. printf("Inserisci il tuo segnale digitale :\n");
  37. scanf("%s",user_imput);
  38.  
  39. int cont = 0;
  40. char stringHelper[3]; //3 perchè c'è anche il terminatore, dubito tu lo userai ma nel dubbio non corriamo il rischio
  41.  
  42. cont=allocate(&stringHelper, user_imput, cont);
  43.  
  44. if(strcmp(start_1, stringHelper)==0 || strcmp(start_2, stringHelper)==0) {
  45. printf("Inizio la conversione");
  46. } else {
  47. exit_while += 2; //Così non entra nel while
  48. }
  49.  
  50. while(exit_while <= 2) {
  51.  
  52. cont=allocate(&stringHelper, user_imput, cont); //Scorre l'user_imput e alloca i caratteri a due a due nella stringa d'appoggio
  53.  
  54. if(strcmp(stringHelper, choice_aa) == 0 || strcmp(stringHelper, choice_bb) == 0) {
  55. printf("1\n");
  56. }
  57.  
  58. if(strcmp(stringHelper, choice_ab) == 0 || strcmp(stringHelper, choice_ba) == 0) {
  59. printf("0\n");
  60. }
  61.  
  62. if(strcmp(stringHelper, stop_1) == 0 || strcmp(stringHelper, stop_2) == 0) {
  63. return -1;
  64. exit_while = exit_while + 2;
  65. }
  66. }
  67. return 0;
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement