#: 8639 S3/Languages
08-Dec-90 11:32:10
Sb: #8589-#'C' problem
Fm: Jim Peasley 72726,1153
To: Pete Lyall 76703,4230 (X)
Pete;
My weekly question on "C" this week is on memcpy and strcat. I seem to be
missing the boat somehow, and would appreciate a "pointer" to whtre I'm
erring.
>> inline = "01/22/54Tiny Tim*Birthday" << addr. passed to funct. 'print_event'
print_event(inline,yr)
char *inline;
int yr;
{
int s_len,
ev_len;
char date[6],
*eptr,
name[32];
memcpy(date,inline,5); /* pull in 1st 5 bytes */
strcat(date,'\0'); /* and null term it */
eptr = strchr(inline,'*'); /* loo' for delimiter */
s_len = strlen(eptr); /* get length of event + '*' */
ev_len = strlen(inline + 8); /* get length of instring - date*/
memcpy(name,(inline + 8),(ev_len - s_len)); /* copy only name */
strcat(name,'\0'); /* and null term it */
printf("\n%s %s",date,name);
return;
}
>> date = "01/22 %#Tiny Tim%#&$!"#$!"
>> name = "Tiny Tim%$#!%$%!"#$#$"
In both cases, my strings don't get null terminated and it prints garbage
chars after them.
...Jim
There are 3 Replies.
|