TIP: Click on subject to list as thread! ANSI
echo: cis.languages
to: Jim Peasley 72726,1153 (X)
from: Pete Lyall 76703,4230
date: 1990-12-08 13:31:34
subject: #8639-#`C` problem

#: 8642 S3/Languages
    08-Dec-90  13:31:34
Sb: #8639-#'C' problem
Fm: Pete Lyall 76703,4230
To: Jim Peasley 72726,1153 (X)

Jim - 
 
I saw Bruce's answer - that's the crux of the problem. Strcat assumes
that the string is already null terminated (that's how it knows
where to append whatever it's appending).
 
Memcpy() is useful for raw bytes (i.e. like copying whole
structures).... strncpy or strcpy are usually fine for characters.
Also, with mem???(), I believe there's a possibility of a byte order
problem if you move between CPU families. I'm not sure of that
though...  Anyway, given your situation, here's how I might approach it:
 
** the year, and have passed it to the function.
*/
 
print_record(recptr, year)
char *record;
int year;
        {
        char date[6], name[32];
        char *evptr;
 
        date[0] = '\0';                        /* just to be sure... */
        name[0] = '\0';                        /* that they're empty */
        
        strncpy(date, recptr, 5);        /* get MM/YY */
        date[6] = '\0';                        /* null terminate it */
 
        evptr = strchr(recptr, '*');        /* find the delimiter */
        if(evptr == NULL)
                {
                fprintf(stderr,"No delimiter found in record '%s'\n", 
                    recptr);
                return(-1);                /* return error to caller */
                }
        /* This will do 2 things: a) Terminate the name field
        ** and b) bump evptr so that it points to the event.
        */
                
        *evptr++ = 0;                
        strncpy(name, recptr+8, 31);  /* copy upto 31 chars */
        name[31] = '\0';  /* just in case we truncated name */
 
        printf("Date: %s  Name: %s  Event: %s\n", date, name, evptr);        
        }

=================================================================
Pete

P.S. I enjoy the questions

There is 1 Reply.

SOURCE: compuserve via textfiles.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.