Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 void * problem for spreadsheet
Index -> Programming, C++ -> C++ Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
ramaadhitia




PostPosted: Sun Nov 26, 2006 11:46 pm   Post subject: void * problem for spreadsheet

Well hello everybody.i planned to develop simple spreadsheet for my homeworks,and then
i decided to use List instead of matrix to represent the spreadsheet cell.

well, code below is type declaration for my list in file matriks.h
code:


/********** DEKLARASI matriks  **********/
/* File : matriks.h        */
/* deklarasi list untuk representasi sel pada matriks */
#ifndef matriks_H
#define matriks_H
#include "boolean.h"
#include <stdlib.h>

typedef struct
{
        void *value;
        int tipe;
}infotype;

typedef struct tElmtCell *address;

typedef struct tElmtCell
{
        infotype *Info;
        int row;
        int column;
        address Next;
}ElmtCell;


typedef struct
{
        address FirstCell;
}Matriks;

/*** Selector Notation***/

#define Nil       NULL
#define First(M)  (M).FirstCell
#define NextCell(C)  (C)->Next
#define Info(C)  (C)->Info->value
#define Tipe(C)  (C)->Info->tipe
#define Row(C) (C)->row
#define Column(C) (C)->column


/*** Prototype Primitif ***/

void CreateMatriks(Matriks *M);
boolean IsEmptyMatriks(Matriks M);
address Allocate(int tipe,void *value,int row,int column);



The list node contains structure named infotype which hold the value of cell and the Value type.1 for integer type,2 string for type,and 3 for storing formula.So i use void * in order to be able to store any kind of data type (integer,string,etc)


this is file matriks.c contains function body from matriks.h

code:


void CreateMatriks(Matriks *M)
{
        First(*M) = Nil;
}

boolean IsEmptyMatriks(Matriks M)

{
        return (First(M) == Nil);
}


address Alllocate(int tipe,void *value,int row,int column)
{
       
        address P;
        printf("setelah alokasi \n");
        P=(address) malloc(sizeof(ElmtCell));
        printf("alokasi \n");
        if (P!=Nil)
        {
                Row(P) = rows; 
                Column(P) = column;
                Tipe(P)  = tipe;
                Info(P)  = isi;
                NextCell(P) = Nil;           
        }
       
        return (P);
}



well the problem is when i want to allocate some memory space for new list node,i use
Allocate function (umm, i made this function,you can see the function body in code above)


the strange part is ,i can only use the allocate function just once.you can try the code below to test the allocate function

code:



#include "matriks.h"

int main (void)
{
        Matriks M1;
        CreateMatriks(&M1);
        address P = Allocate(1,(void *)1,1,1);
        address Q = Allocate(1,(void *)2,2,1);
        /*
        printf("it works \n");
        //InsertElement(&M1,1,1,1,1);
        printf("info cell is : %d \n",Info(First(M1)));
        //InsertElement(&M1,2,"rama adhitia",2,23);
        printf("hehe\n");*/
        scanf("%d");
        return 0;
}



when i allocate address P, the allocate function works nicely,but when i allocated address Q
the function didnt works.i think this is happen because i use void * to store value
in infotype structure.what's my mistake?

Please help me guys!!
(i use mingw compiler (gcc))
Sponsor
Sponsor
Sponsor
sponsor
Monstrosity_




PostPosted: Mon Nov 27, 2006 2:48 pm   Post subject: Re: void * problem for spreadsheet

ramaadhitia wrote:
Well hello everybody.i planned to develop simple spreadsheet for my homeworks,and then
i decided to use List instead of matrix to represent the spreadsheet cell.

Does that mean this is an assignment, or it's to help you do your assignments?

ramaadhitia wrote:
when i allocate address P, the allocate function works nicely,but when i allocated address Q the function didnt works.i think this is happen because i use void * to store value in infotype structure.what's my mistake?

No one here can help you until you post all of the code or post to code correctly. The code you posted makes reference to variables that are never declared anywhere (like rows and isi). Once you post the actual code that compiles, and specify what's going wrong other then "the function didn't works" (like an access violation perhaps), then we can talk about the other errors.
ramaadhitia




PostPosted: Tue Nov 28, 2006 2:56 am   Post subject: Thanks for the attention

i didn't mean to have somebody do my homework.my question just a little piece of my assignment.but now i have figured out the answer.

by the way,thanks for your attention,i really appreciate it
Display posts from previous:   
   Index -> Programming, C++ -> C++ Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 3 Posts ]
Jump to:   


Style:  
Search: