Created
May 19, 2018 05:14
-
-
Save julioflima/151a44fd3a1cf582e3b007dec79da5dc to your computer and use it in GitHub Desktop.
split in C created by juloko2 - https://repl.it/@juloko2/split-in-C
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <string.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
int main () { | |
char str[80] = "step(145621900,54544660)"; | |
char duty[10]; | |
char time[20]; | |
int firstP = strcspn(str, "("); | |
int secondP = strcspn(str, ","); | |
int thirdP = strcspn(str, ")"); | |
for(int i = 0 ; i<strlen(str); i++){ | |
if(i < secondP - firstP - 1){ | |
duty[i] = str[firstP+i+1]; | |
} | |
else if (i<strlen(duty)){ | |
duty[i] = '\0'; | |
} | |
if(i < thirdP - secondP - 1){ | |
time[i] = str[secondP+i+1]; | |
} | |
else if (i<strlen(time)){ | |
time[i] = '\0'; | |
} | |
} | |
printf("By string:\n"); | |
printf("%s\n",str); | |
printf("%s\n",duty); | |
printf("%s\n",time); | |
printf("%d\n",firstP); | |
printf("%d\n",secondP); | |
printf("%d\n",thirdP); | |
printf("By value:\n"); | |
printf("%d\n",atoi(duty)); | |
printf("%d\n",atoi(time)); | |
return(0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment