Skip to content

Instantly share code, notes, and snippets.

@zaman
Created November 21, 2010 17:10
Show Gist options
  • Save zaman/708911 to your computer and use it in GitHub Desktop.
Save zaman/708911 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define MAXLINE 1024
char * KOMUT[MAXLINE];
int wspace(char c) {
return c == ' ' || c == '\n';
}
char split(char l[]) {
char s[MAXLINE];
int i, j, k;
int state = 1;
for (j = 0, i = 0, k = 0; i < strlen(l); i++) {
if (! wspace(l[i])) {
s[j++] = l[i];
state = 1;
}
if ((state == 1 && wspace(l[i])) || l[i + 1] == '\0') {
s[j] = '\0';
KOMUT[k++] = strdup(s);
state = 0;
j = 0;
}
}
}
int main() {
split("merhaba dunya");
printf("1. %s \n",KOMUT[0]);
printf("2. %s \n",KOMUT[1]);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment