[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[ale] C and segmentation fault
- Subject: [ale] C and segmentation fault
- From: chrish at ifsintl.com (Christopher Hamilton)
- Date: Thu, 17 Jul 1997 16:30:05 -0400
>main()
>{
> char s1[BIGENOUGH];
> char s2[WHATEVER];
>
> strcpy(s1, "S1");
> strcpy(s2, "S2");
> strcat(s1,s2);
>
> printf("s1: %s\ns2: %s\n", s1, s2);
>}
If you're going this way, but need the ability to easily append extra
characters to a string (e.g. s1), to go along with the initial mail
using pointers, you can try using a couple of macros that I wrote to
help me out a bit:
#include <stdlib.h> /* required for malloc/realloc */
#define STRCPY(d,s) d=(char *)malloc(strlen(s)+1);strcpy(d,s)
#define STRCAT(d,s) d=(char *)malloc(d,strlen(d)+strlen(s)+1);strcat(d,s)
main()
{
char *s1,*s2;
STRCPY(s1,"S1");
STRCPY(s2,"S2");
STRCAT(s1,s2);
printf("%s\n",s1);
}
---
Christopher Hamilton Internal System Administrator
chrish at ifsintl.com IFS International, Inc.