words.txt in C

How would one add the words.txt along with the libraries in C. My friend told me how to do it in C++, but I'm doing C. #include <words.txt> doesn't work.

Thanks in advance!
I think the question being asked here is how to do File I/O in C.
It would help us if we had some more background on your problem and what you're trying to do. :)

If you are trying to do File I/O in C like Whovian and I are guessing, would this help? http://www.cprogramming.com/tutorial/cfileio.html

-Albatross
1. Whovian's guess is correct.
2. All the background that I can possibly give you: I'm trying to solve http://projecteuler.net/problem=42. Please: no hints or give-aways on how to solve the problem. Just how to use words.txt.

Thanks in advance!
Ah, okay. Well, that number of characters doesn't take up too much memory. You could store the whole file on the heap.

If you choose to do that, then these two C functions might also help to figure out how large the file is (keep in mind that ftell is not guaranteed to return the number of bytes since the start on non-binary files... how might you fix this?)
http://www.cplusplus.com/reference/clibrary/cstdio/fseek/
http://www.cplusplus.com/reference/clibrary/cstdio/ftell/

-Albatross
Last edited on
What about using fscanf?
http://www.cplusplus.com/reference/clibrary/cstdio/fscanf/

Can't you use that in a loop to check the words one at a time? Or is that one of those functions that are bad and should be avoided?
http://www.gidnetwork.com/b-56.html
I must improve on making my question clearer. I'm trying to words.txt in my C program. We #include libraries. But, obviously, #include <words.txt> doesn't work. Then, how do we use words.txt in the program? That's my question.

Sorry for the trouble and thanks for trying to help me out.
Ahaanomegas,

Here is the sample how to use words.txt in your program.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <iostream>
#include <fstream>

using namespace std;

int main ()
{
fstream inFile;
inFile.open("words.txt")  

int x;
here do a loop or something
inFile>>x;

inFile.close();
return 0;
}
@poloblue64
That's a C++ solution. The OP asked for help in C. :/
How would one add the words.txt along with the libraries in C. My friend told me how to do it in C++, but I'm doing C.


@Ahaanomegas
I posted a link earlier, did it not help you? If not, then here's another link to try:
http://www.cs.bu.edu/teaching/c/file-io/intro/

Good luck!

-Albatross
Topic archived. No new replies allowed.