Hello. I was wondering how to read strings from a file word by word and store the words into an array in c. I am having to write a program that tests words to see of they are palindromes from a little paragraph i wrote in a file. I've been trying to figure it out all afternoon with no luck.:(
bemo55
0
Newbie Poster
Recommended Answers
Jump to Postfgets and strtok would be good places to start. Do you know how many strings you will be reading? If you don't it will make the array part a little more difficult.
Jump to PostHere you have a small example :
#include <stdio.h> main() { FILE *fp; fp = fopen("test.txt", "w"); fscanf(fp, "%s", buffer); printf("Read Buffer: %s\n", %buffer ); flcose(fp;); }
To better understand fscanf try viewing : http://irc.essex.ac.uk/www.iota-six.co.uk/c/i4_fwrite_fscanf_fprintf.asp
All 6 Replies
death_oclock
103
Posting Whiz
jen140
0
Junior Poster
death_oclock
103
Posting Whiz
bemo55
0
Newbie Poster
bemo55
0
Newbie Poster
bemo55
0
Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.