Hi members,
I'm fairly new to C programming. I've worked in python, and bash.
I want to split string and store it in an array:
Function takes: character array, and the words in it.
Code:
void array_of_str(char *line, unsigned int count){
unsigned int i=0;
char *array[count];
char *p;
p=strtok(line,'\t');
while(p !=NULL){
printf("Value of I is %d\n",i);
array[i++]=p;
p=strtok(NULL,'\t');
}
printf("##--##\n");
}
I compile my code as:
gcc -g -Wall -Wextra *.c -o program_parse -std=gnu99
I get warnings as:
Code:
warning: implicit declaration of function ‘strtok’ [-Wimplicit-function-declaration]
p=strtok(line,'\t');
warning: assignment makes pointer from integer without a cast
p=strtok(NULL,'\t');
In my headers in main file, I've:
Code:
#define _GNU_SOURCE
#include<string.h>
When I run my code, i get error:
Code:
Segmentation fault (core dumped)
String I'm passing:
denovo2819 A15_94875 B13_87655 B23_17316
count=4
Unable to solve this.
Any help would be appreciated.
thanks.