![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here. |
More UNIX and Linux Forum Topics 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 05:14 AM |
| move output of awk to array | amitrajvarma | Shell Programming and Scripting | 14 | 12-21-2007 06:12 AM |
| output of an array | ragha81 | Shell Programming and Scripting | 3 | 03-22-2007 04:30 PM |
| directing output | Cynergetix | UNIX for Dummies Questions & Answers | 1 | 03-21-2002 12:59 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate 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. |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|