I am writing a program which takes two sets of inputs from stdin. Then i need to break up each of these sets into strings using a tokenizer. I want to use a function to do that, so that my program can reuse that function. This is what I have so far.
Code:
#include<string.h>
#include<stdio.h>
int printRecord(char *line)
{
char *v_array[50];
int loop;
char v_line[1024];
strcpy(v_line,line);
v_array[0]=strtok(v_line," ");
printf("zeroth element is %s\n",v_array[0]);
if(v_array[0]==NULL)
{
printf("No test to search.\n");
return 0;
}
for(loop=1;loop<50;loop++)
{
v_array[loop]=strtok(NULL," ");
printf("element is %s\n",v_array[loop]);
if(v_array[loop]==NULL)
break;
}
for(loop=0;loop<50;loop++)
{
if(v_array[loop]==NULL)
break;
printf("Item #%d is %s.\n",loop,v_array[loop]);
}
return 0;
}
int main(void)
{
int i;
char search_string[]="Woody Norm Cliff";
printRecord(search_string);
return 0;
}
Now I want to use the function printRecord in a way that it returns me the set of items tokenized. Either in an array or any other way. How to do that in C?