Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7615701
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T02:42:24+00:00 2026-05-31T02:42:24+00:00

I have to do this exercise: Do an application in C that manages a

  • 0

I have to do this exercise:

Do an application in C that manages a matrix of integer named “M” and a list of integer named “L”. M is a square matrix [nxn] with n chosen by user dynamically. Then do this function:

  • Serialize: given the “M” matrix it return the list L with n^2 elements. The elements of the list are the element of M ordered by row from the first to the second.

The second function:

  • Deserialize: given the list L with n^2 elements, it return a matrix [nxn] with elements of L ordered by column.

So main() must be:

  • User give the dimension of matrix (n) and fill the matrix with some integer.
  • Then call serialize function, print the list serialized
  • add the value 5 to every value of list
  • and call deserialize function
  • and print the matrix given by the last function.

(All allocation must be dynamic.)

I have tried this:

#include <stdio.h>
#include <stdlib.h>

int main(){
    int n,i,j;
    printf("Give the dimension of matrix [nxn]: ");
    scanf("%d",&n);
    int **M;
    M = (int**)malloc(n*sizeof(int*));
    for(i=0;i<n;i++){
        M[i] = (int*)malloc(n*sizeof(int*));
    }
    int *L = serialize(M,n);
    int size = n*n;

    for(i=0;i<size;i++){
        printf("L[%d]= %d",i,L[i]);
    }
    for(i=0;i<size;i++){
        L[i] = L[i]+5;
    }
    int **M2 = deserialize(L,n);
    for(i=0;i<n;i++){
        printf("\n");
        for(j=0;j<n;j++){
            printf("%d",M2[i][j]);
        }
    }
    free(M);
    free(M2);
    free(L);
}

int serialize(int** M,int n){
    int *L;
    int i,j;
    int size = n*n;
    L = (int*)malloc(size*sizeof(int));
    for(i =0;i<size;i++)
        L[i]=M[i/size][(int)i%size];

return L;
}

int deserialize(int* L,int n){
    int** M;
    int i,j;
    M = (int**)malloc(n*sizeof(int*));
    for(i=0;i<n;i++){
        M[i] = (int*)malloc(n*sizeof(int*));
    }
    int size = n*n;
    for(i=0;i<size;i++)
        M[i/size][i%size]=L[i];

    return **M;
}

The compiler give me the errors:

Esercizio.c: In function ‘main’:
Esercizio.c:22: warning: initialization makes pointer from integer without a cast
Esercizio.c:31: warning: initialization makes pointer from integer without a cast
Esercizio.c: At top level:
Esercizio.c:43: error: conflicting types for ‘serialize’
Esercizio.c:22: error: previous implicit declaration of ‘serialize’ was here

What can I do?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T02:42:25+00:00Added an answer on May 31, 2026 at 2:42 am

    in deserialize, you should return M, not **M:

    int** deserialize(int* L,int n){
        int** M;
        //....    
        return M;
    }
    

    Also, you need to declare the functions before calling them. Before main add:

    int* serialize(int** M,int n);
    int** deserialize(int* L,int n);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code in jQuery, that I want to reimplement with the prototype
I have this idea for a free backup application. The largest problem I need
I have this RewriteRule that works too well :-) RewriteRule ^([^/]*)/$ /script.html?id=$1 [L] The
I have this line in a useful Bash script that I haven't managed to
I'm developing a Grails web application (mainly as a learning exercise). I have previously
I have a WCF solution that consists of the following class libraries: Exercise.Services: Contains
I have an exercise in problem solving for those who like that kind of
I have a mission critical Perl-CGI server-side application that I need to extend or
I'm designing an application that supports plugin development. Its more of a learning exercise.
I'm new to MongoDB and as an exercise I'm building an application that extracts

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.