How is .txt file different from a .dat file in C?

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

Was this solution helpful to you?

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:

Just Added Q & A:

Find solution

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.