Hi
i am trying to write a function in C which will print a substring oout of a string in loop with a token seperator.
For example
i have a file which contains the following lines
aaaaa
bbbbb
ccccc
ddddd
i have to read each line and then copy to a variable. Once end is reached , i have to start from again
i am trying to use strtok but how to go to the starting of function and then strtok again
Below is the code snippet
#include <stdio.h>
#include<string.h>
char *result;
void new();
int main(void) {
int c=0,i,n;
FILE *fp;
char str[40000];
fp=fopen("test.txt","r");
n=fread(str,1,40000,fp);
printf("str value is <%s>\n",str);
result = strtok(str,"\n");
for(i=0;i<50;i++)
{
printf("result value is <%s>\n",result);
new();
result=strtok(NULL,"\n");
}
return(0);
}
void new()
{
char *temp;
printf("result value in function is <%s>\n",result);
strcpy(temp,result);
printf("temp value is <%s>\n",temp);
}
Thanks
Vit