Possible Duplicate:
How to copy char *str to char c[] in C?
char *token = "some random string";
char c[80];
strncpy(c, token, sizeof c - 1);
c[79] = '\0';
char *broken = strtok(c, "#");
Possible Duplicate:
How to copy char *str to char c[] in C?
char *token = "some random string";
char c[80];
strncpy(c, token, sizeof c - 1);
c[79] = '\0';
char *broken = strtok(c, "#");
Your code does not crash for me in the following:
#include <string.h>
main()
{
char *token = "some random string";
char c[80];
strcpy( c, token);
strncpy(c, token, sizeof c - 1);
c[79] = '\0';
char *broken = strtok(c, "#");
}
This code works, have you specified the correct includes?
#include <string.h> /*
#include <stdio.h>
#include <stdlib.h>
int
main() {
/* ORIGINAL CODE */
char *token = "some random string";
char c[80];
strcpy( c, token);
strncpy(c, token, sizeof c - 1);
c[79] = '\0';
char *broken = strtok(c, "#");
/* ADDED THE FOLLOWING LINES */
printf("%s\n", broken);
exit(1);
}