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

fgets 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.

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.

p.s. My file has 63 strings.

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

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.