Good day!
I am only a beginner at c programming and I need some help to clarify the correct use of fseek function. Here is my program this is only for letter a:
Code:
#include <stdio.h>
#include <conio.h>
#include <string.h>
#define SIZE 10
#include <io.h>
struct entry{
char results[50];
};
main()
{
char letter[SIZE];
FILE *fp, *fp2;
int num =0;
char add, newword[50], word[10], buffer[50];
long size, len;
struct entry buffers;
printf ("Enter a letter:\t");
gets(letter);
strlwr(letter);
if (letter[0] == 'a')
{
if ((fp = fopen ("a.txt", "r")) != NULL)
{
printf("Type a word:\n");
gets(word);
len = strlen(word);
fseek(fp, (long) (len*sizeof(struct entry)), 0);
fread(&buffers, sizeof(struct entry), 1, fp);
fprintf(stdout, "%s", buffers.results);
fclose(fp);
}}
getch();
}
My target is to create a dictionary program.
This is my expected output:
Enter a leter: a
Enter a word: abaculus
abaculus small tile for mosaic
But the result of my actual program is inaccurate.
hoping for your response. Thankyou.