Advertisement
Guest User

Untitled

a guest
Apr 19th, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.90 KB | None | 0 0
  1. int toMorse(FILE *instream, char **mcmsg_ptr){
  2. // Insert code here
  3. int msgSize = 100;
  4. *mcmsg_ptr = malloc(msgSize);
  5.  
  6. int f = fgetc(instream);
  7. int size = 0;
  8. int space = 0;
  9.  
  10. while(f != EOF)
  11. {
  12. if( f >= 97 && f <= 122)
  13. {
  14. f = f - 32;
  15. }
  16. if( f >= 33 && f <= 90 )
  17. {
  18. space = 0;
  19. int index = f - 33;
  20. char * tmp1 = *(MorseCode + index);
  21.  
  22. int count = 0;
  23. while(*(tmp1 + count) != '\0')
  24. {
  25. if( size + 10 >= msgSize )
  26. {
  27. msgSize += sizeof(char) * 20;
  28. *mcmsg_ptr = realloc(*mcmsg_ptr, msgSize);
  29. }
  30. *(*mcmsg_ptr + size) = *(tmp1 + count);
  31. count++;
  32. size++;
  33. }
  34. *(*mcmsg_ptr + size) = 'x';
  35. size++;
  36. }
  37.  
  38. if( f == 32 )
  39. {
  40. if( space != 1)
  41. {
  42. *(*mcmsg_ptr + size) = 'x';
  43. size++;
  44. space = 1;
  45. }
  46. }
  47. f = fgetc(instream);
  48. }
  49. if( size == 0 && f == EOF )
  50. {
  51. *(*mcmsg_ptr + size) = 'x';
  52. size++;
  53. }
  54. if( space != 1 )
  55. {
  56. *(*mcmsg_ptr + size) = 'x';
  57. size++;
  58. }
  59. *(*mcmsg_ptr + size) = '\0';
  60.  
  61. return 1;
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement