i have the following code
Code:
typedef struct nod
{
int inf;
struct nod *next;
} nod;
int main(int argc,char **argv)
{
...
read(argv[1],a,b,&sgna,&sgnb);
...
}
void read(char *fis,nod *a,nod *b,int *sgna,int *sqnb)
{
FILE *f=fopen(fis,"rt");
int c;
nod *t;
if(f==NULL)
{
exit(-1);
}
a=(nod*)malloc(sizeof(nod));
t=a;
while((c=fgetc(f))!='\n')
{
if(c=='-') *sgna=1;
else
{
t->inf=c-'0';
t->next=(nod*)malloc(sizeof(nod));
t=t->next;
}
}
/*
while(a->next!=NULL)
{
printf("%d ",a->inf);
a=a->next;
}
printf("\n");
*/
fclose(f);
}
The problem is that outside the read function the nod structure doesn't preserve its values. Inside the function it can be printed just fine.
What could the problem be ?