How do i call for a txt file in c coding?
-
I can not for the life of me remember how to call for a txt file in my c coding. So my assignment is to create a yahtzee game (i'm sure a ton of you have heard of this) And I have 4 files so far I have my header file my programs file main.c and a txt file I am working on displaying the menu and my first option is to display the rules well I am trying to use a txt file which I have set up and I have the text I want displayed in it their and I am using a while loop to determine what option to do and I am trying to return my rules from the txt file
-
Answer:
Depends on if you are using Windows or Linux. In Windows you use CreateFile(), OpenFile(), _open(), fopen(). In Linux fopen() is the only choice. But there is really no advantage to using files for something as short as rules really. Just use a bunch of const chars instead. Much easier. You could put them in an array if you want. /* fopen example */ #include <stdio.h> int main () { FILE * pFile; pFile = fopen ("myfile.txt","w"); if (pFile!=NULL) { fputs ("fopen example",pFile); fclose (pFile); } return 0; }
David at Yahoo! Answers Visit the source
Other answers
You need to use C file pointers. Then, you can use the functions such as fscanf and fprintf to read and write to the file.
Related Q & A:
- How do I call an objective-c method?Best solution by Stack Overflow
- How can I programmatically extract a file quickly and efficiently within Android?Best solution by Stack Overflow
- How to delete a line from a .txt file in node.js?Best solution by c-sharpcorner.com
- How often should I call about a job interview?Best solution by workcoachcafe.com
- How do I call a cell phone in Australia?Best solution by wiki.answers.com
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.