Quote (Eep @ Sep 29 2012 10:43pm)
that code doesnt make sense lol. what are you trying to do? the cmp string isnt being used and i cant see how you are getting that output from that code lol
if you want to split a string try something like this
im also pretty sure there is a split method within the STRING class
Code
#include <stdio.h>
#include <stdlib.h>
//need to include this for the split function
#include <string.h>
void split(char *input, char *dilimeter, char **output);
int main()
{
char userInput[81];
char *functionOutput[80];
int i = 0;
printf("Enter a string to test the split function\n");
fgets(userInput, sizeof(userInput), stdin);
split(userInput, ".", functionOutput);int i
while(functionOutput[i] != '\0')
{
printf("%s\n", functionOutput[i]);
i++;
}
getchar();
return 0;
}
void split(char *input, char *dilimeter, char **output)
{
int i = 0;
output[0] = strtok(input, dilimeter);
while(output[i] != NULL)
{
i++;
output[i] = strtok(NULL, dilimeter);
}
output[i + 1] = '\0';
}
edit:: i could of changed it to return a char * so that i wouldnt need to include a **output buffer.
would also make the call to the function cleaner by way of
Code
output = split(input,' ');
This post was edited by AbDuCt on Sep 30 2012 12:43am