View Single Post
Old 10-18-2004, 06:09 AM   #2 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,720
redhead is on a distinguished road
Try to keep control of what you're passing between the different functions:
Code:
void getLen(kata L)
{	
	int i=0;
	while(L.TKata[i ] != '\0')
	{i++;}
	L.len = i-1;	  	
}
Here you're passing a copy of kata, not the object itself, so any assignment of L.len is lost on exit of function scope.
Code:
void getLen(kata* L)
{
  int i=0;
  while(L->TKata[i ] != '\0')
  {i++;}
  L->len = i-1;	  	
}
....
getLen(&v);
will do, what you possibly want here, where the len member of the passed kata is assigned the length (altho you're off by one)

When copying, you need to think in the same direction.
Altho your code does what it should do, theres way too much pointer to pointer arritmetic in it for my taste, instead you can use
Code:
void CopyKata (kata*  Tin , kata *Tout)
{	
  int i;
  Tout->len = Tin->len;
  for (i = 1; i < (Tin->len +1);i++)
  {
    Tout->TKata[i ] = Tin->TKata[i ];
  }
}
...
CopyKata(&Input, &T.TFile[1]);
CopyKata(&T.TFile[1], &T.TFile[2]);
Another thing, I dont like the SetFile() you're using, when passing Tab T to it, you're relying on the usual pass by value effect to handle everything you've put into the Tab struct.
A better way here, would be to use pass by reference aswell.
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote