strcat Core Dump
I have used the sys function to get the pathname as follows...
Code:
#include <string.h> I need to pass this to the system function (commented...) Thank you. -Monil |
The memory for cmd and dir are allocated at compile time itself. You are tyring to copy another string into the same variable without allocating more memory. Thats why it is dumping.
Try allocating for cmd, dir and then reallocate for dir and proceed. int main() { char *cmd; char *dir; int newsize; cmd = (char *) calloc (20,1); dir = (char *) calloc (20,1); strcpy (cmd, "asas/sdfsdf/ghgf"); strcpy (dir, "dirname "); newsize = strlen(cmd) + strlen(dir) +1; // 1 for NULL dir = (char *) realloc (dir, newsize); strcat(dir,cmd); puts(dir); //system(dir); return 0; } HTH |
Also check for the return status of calloc and realloc.
|
Quote:
e.g.: Code:
int main() |
Or, easier:
Code:
#include <stdio.h> |
All times are GMT -5. The time now is 11:46 PM. |