I've been trying to read in data from a file by tokenizing it first. In this example, I've made it so that it asks you to first input the data in yourself (which I've made sure works), and then read it in but tokenize with spaces. So if I was to enter 'Hello World' it should return: 'Hello, World'. Here's my code.
char fname[] = "myfile";
FILE *fp;
fp = fopen(fname, "w+");
char buffer[20];
sprintf(prompt, "Enter your string: ", MAX_TAN_INPUT);
getString(number, MAX_TAN_INPUT, prompt);
printf("\n");
if (fp == NULL)
{
fprintf(stderr, "Unable to open file %s\n", fname);
}
else
{
printf("YAYYY. It opened!\n");
fprintf (fp, "%s\n", number);
fseek(fp, SEEK_SET, 0);
fread(buffer, strlen(fp)+1, 1, fp);
printf("%s\n", buffer);
{
/* No more data read. */
}
}
printf ("HERE\n");
fclose(fp);
Any help would be greatly appreciated guys :)