![]() |
|
|
|||||||
| Home | Forums | Register | Rules & FAQ | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here. |
Other UNIX.COM Threads You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| bash:awk output into an array | phamp008 | Shell Programming and Scripting | 2 | 03-16-2008 01:14 AM |
| move output of awk to array | amitrajvarma | Shell Programming and Scripting | 14 | 12-21-2007 02:12 AM |
| output of an array | ragha81 | Shell Programming and Scripting | 3 | 03-22-2007 12:30 PM |
| directing output | Cynergetix | UNIX for Dummies Questions & Answers | 1 | 03-21-2002 08:59 AM |
![]() |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
|||
|
Regardign strtok() output directing to 2-D string array
Hi,
I just wrote a program in C to split a comma seperated string in to group of strings using strtok() function. The code is: Code:
int main()
{
char *temp;//not used here but basically we extract one string after another using strtok() and assign to a string pointer defined like this.
char *str="aa,bb,cc,dd";
int count=0;
for(int i=0;i<strlen(str);i++)
{
if(str[i]==',')
count++;
}
char *ss[count];//2-d array where i want to store splitted results
int j=0;
*(ss+j)=strtok(str,",");
while(*(ss+j)!=NULL)
{
*(ss+j)=strtok(NULL,",");
j++;
}
//print output
for(int i=0;i<strlen(*ss);i++)
printf("%s\t",*(ss+i));
return 0;
}
The program compiles without error(please bear any syntax error, since i typed in hand without the code with me but the orignial program compiles successfully) but i am getting runtime error like 'Segmentation Fault'. I hope there needs to be proper memory handling here which i am not sure of. Please help me in getting this splitted set of strings to a new 2-D array. Thanks in advance. |
| Forum Sponsor | ||
|
|