I am trying to develop a basic shell. For that shell I need a C function to parse a string. As i am new to C I tried to develop a basic function and it gives me a segmentation fault error. Please tell me what I am missing.
#include<string.h>
#include<stdio.h>
void parse(char *msg);
int main()
{
char *msg = "This is a message";
parse(msg);
}
void parse(char *msg){
char *mm;
mm = msg;
char *tok;
tok = strtok(mm," ");
while(tok == NULL){
tok = strtok(NULL," ");
printf("%s \n",tok);
}
}
Error Message (Runtime)
Segmentation fault (core dumped)
Thanks in advance