hi,
i managed to get my struct to work.the problem i am having now is i am trying to use calloc memory allocation but i keep getting a segmentation fault and i don't know how to fix it. i don't think i am declaring the calloc properly and storing the result of encode properly.
here is my code that i am using.
#include <stdio.h>
#include <stdlib.h>
typedef struct code1
{
unsigned short key[2];
unsigned short text[2];
}code;
void encode(short* v, short* k)
{ ... }
void decode(short* v,short* k)
{ ... }
main(int argc, char *argv[])
{
unsigned short key1[2],key2[2];
unsigned short p[2],c[2];
struct code1 *test, *entry;
entry = (unsigned short *) calloc(2, sizeof (code));
key1[0]=0x0000;
key1[1]=0x0000;
short i;
p[0]=0x0001;
p[1]=0x0002;
for (i=0; key1[0] < 0x0002; i++)
{
for (i=0; key1[1] < 0x000A; i++)
{
encode(p, key1);
test[i].key[0] = key1[0];
test[i].key[1] = key1[1];
test[i].text[0] = p[0];
test[i].text[1] = p[1];
}
}
} //end main
can anybody help?
thanks,
sc
|