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.:(

I hate to sound like a prick but... using fscanf is generally a bad idea. There are plenty of reasons, but a big one is that most people don't really understand what its doing. Therefore it usually only works with carefully formatted input. Or by accident.

I have looked at strtok but I didnt think that it would work with data i am reading in. All the examples i seen were declaring the array as a certain string like
char array1=" your string here"
and then using strtok. I didn't really understand how to use strtok.

Nevermind. I got the tokenizing function to work:)..Now ive just got to implement my palindrone function. Thanks for the help guys.

This article has been dead for over six months. Start a new discussion instead.