Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int toMorse(FILE *instream, char **mcmsg_ptr){
- // Insert code here
- int msgSize = 100;
- *mcmsg_ptr = malloc(msgSize);
- int f = fgetc(instream);
- int size = 0;
- int space = 0;
- while(f != EOF)
- {
- if( f >= 97 && f <= 122)
- {
- f = f - 32;
- }
- if( f >= 33 && f <= 90 )
- {
- space = 0;
- int index = f - 33;
- char * tmp1 = *(MorseCode + index);
- int count = 0;
- while(*(tmp1 + count) != '\0')
- {
- if( size + 10 >= msgSize )
- {
- msgSize += sizeof(char) * 20;
- *mcmsg_ptr = realloc(*mcmsg_ptr, msgSize);
- }
- *(*mcmsg_ptr + size) = *(tmp1 + count);
- count++;
- size++;
- }
- *(*mcmsg_ptr + size) = 'x';
- size++;
- }
- if( f == 32 )
- {
- if( space != 1)
- {
- *(*mcmsg_ptr + size) = 'x';
- size++;
- space = 1;
- }
- }
- f = fgetc(instream);
- }
- if( size == 0 && f == EOF )
- {
- *(*mcmsg_ptr + size) = 'x';
- size++;
- }
- if( space != 1 )
- {
- *(*mcmsg_ptr + size) = 'x';
- size++;
- }
- *(*mcmsg_ptr + size) = '\0';
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement