Home > front end >  Returning array to main from a function in C
Returning array to main from a function in C

Time:12-24

So basically my problem is I want decompress function to sign output of "printf("%.*s", repeat, memset(set, c, repeat));" to array dest and return this dest to main and sign it to Decompressed_Message

here is an image of my problem

here is image of my problem

I want first decompressed version: and second one to be exactly same. But however even I tried sprintf() I wasn't able to make it as I wish

here is my codes

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <ncurses.h>
    
char* Compression(char* Message, int given_count)
{
    int Len;
    char count[given_count];
    int length = strlen(Message);
     
    char* destination = (char*)malloc(sizeof(char) * (length * 2   1));
        
    int i;
    int j=0;
    int k;
     
    for (i = 0; i < length; i  ) {
        destination[j  ] = Message[i];
        Len = 1;
        while (i   1 < length && Message[i] == Message[i   1]) {
            Len  ;
            i  ;
        }
     
        sprintf(count, "%d", Len);
     
        for (k = 0; *(count   k); k  , j  ) {
            destination[j] = count[k];
        }
    }
    destination[j] = '\0';
    return destination;
    free(destination);
}
    
char* Decompression(char *Compressed_Message, char* Message){
        
    int length = strlen(Message);
    char* dest = (char*)malloc(sizeof(char) * (length * 2   1));
        
    while(*Compressed_Message){
        int repeat = 0;
        char c = *Compressed_Message  ;   
        while(isdigit(*Compressed_Message))
        {
            repeat = repeat*10   *Compressed_Message   - '0'; 
        }
        char set[repeat];
        printf("%.*s", repeat, memset(set, c, repeat)); 
        memset(dest, c, repeat);
    }
        
    dest[length] = '\0';
    return dest;
    free(dest);
}
        
int main(void) {
    
    int letters;
    float compression_odd;
    
    printf("Data compressor and decompressor\n\n");
        
    FILE *file;
    char filename[100]="";  
    printf("\n\nPlease Enter the name of file: ");
    scanf("           
  • Related