Fungsi Explode/Split pada String dengan bahasa C

Pernah tahu fungsi explode PHP atau split nya VB.NET? fungsi tersebut sangat berguna bagi kita yang hendak melakukan tokenisasi… nah, kita bisa mencobanya pada bahasa C:
#include
#include
#include

void explode(char str[100],char hasil[10][50],char dasar,int *counter1){
int i,counter2=0;
for(i=0;i<strlen(str);i++){
if(str[i] == dasar){
counter2=0;
*counter1=*counter1 + 1;
}
else{
hasil[*counter1][counter2]=str[i];
counter2++;
}
}
}

void main(){
char str[100],hasil[10][50];
int counter1=0;
printf(“masukkan kalimat : “);fflush(stdin);gets(str);
char dasar = ‘ ‘;
explode(str,hasil,dasar,&counter1);
for(int i=0;i<=counter1;i++){
printf(“%s\n”,hasil[i]);
}
}
Nah silahkan mencoba…

One thought on “Fungsi Explode/Split pada String dengan bahasa C

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s