Question

Note: The answer should be only in C Programming I want a C code to save...

Note: The answer should be only in C Programming

I want a C code to save all the output results into a file. without using the terminal, only using C code

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Please find the commented code below :

------------------------------------------------------------------------------

#include <stdio.h>

int main(void)

{

   //Open a file if it exists, otherwise create one
   FILE *myFile = fopen("writeToThisFile.txt", "w");
   if (myFile == NULL)//If error occurs in opening the file
   {
        printf("Error in opening the file!\n");
        return 1;
   }

   //strings to be written to file
   const char *text = "This will be written to file";
   fprintf(myFile, " %s\n", text);

   //strings to be written to file
   const char *instruction = "This works very similar to printf, but the output goes to file instead of your screen";
   fprintf(myFile, " %s\n", instruction);

   //close the file
   fclose(myFile);

}

-------------------------------------------------------------------------

Please find the screenshot of ouptut below :

1 Some text: Write this to the fil 2 Integer: 1, float: 3.141593 #include <stdio.h> int main(void) writeToThisFle.txt file.txt writeToThisFile.xt this wil1 be written to file This works very sinilar to printf, but the output goes to File instead of your screen FILE myFile- fopen (writeToThisFile.txt, w); if (myFileNULL) printf(Error in opening the file!n): return 1; const char *textThis will be written to file fprintf(myfile, %s\n, text); const char *instruction This works very similar t fprintf(myFile, %s\n, instruction); Plain TextTab Width: Ln 1, Col fclose(myFile);

Add a comment
Know the answer?
Add Answer to:
Note: The answer should be only in C Programming I want a C code to save...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Experiment with the terminal and C programming   I want you to be able to setup a...

    Experiment with the terminal and C programming   I want you to be able to setup a folder, change to a folder, create a new file with the editor (windows version is fine), rename files, delete files, and change permissions. How to create a compiled program Create your source code; lets say it is named test.c Compile it using: gcc test.c –o test Change the permissions to execute for everyone (755) Run it by: ./test Create two programs The first one...

  • I want to write a code in phyton that prints only letters from input but skips...

    I want to write a code in phyton that prints only letters from input but skips two and prints one. I want my program to do this; input = 2ab4c#fd56gjl output = afj So it should completely ignore any character other than letters and print the letters by skipping 2. (Should i use for loop? My classes just beyan so i am guessing the answer code should be a primitive code.)

  • Please use C programming to write a code segment as an answer. Instead of using an...

    Please use C programming to write a code segment as an answer. Instead of using an while-loop like the following code, please implement a code segment by using a do-while loop. What is the output of the code? #include <stdio.h> void main() {        int i = 0;        while (i < 5);        {               printf(“%d ”, ++i);        } }

  • Hi everyone, I have a C programming problem, answers are better with explanations. Background Materials: The...

    Hi everyone, I have a C programming problem, answers are better with explanations. Background Materials: The Task: The Answer: The completed C code. Below is the file charIO4C.c: #include <stdio.h> #include <ctype.h> #define QUIT_LETTER 'q' int main(void) { int c, line_length; // Each pass through the outer loop reads a line of input. while (1) { printf("\nEnter a line of text. (To quit, start the line with %c.)\n", QUIT_LETTER); c = fgetc(stdin); if (c == EOF || c == QUIT_LETTER)...

  • please anyone give homomorphic encryption complete project?? please I want a code in c programming to...

    please anyone give homomorphic encryption complete project?? please I want a code in c programming to implement homomorphic encryption . please actually I am doing a project in cryptography fundamentals calledhomomorphic encryption. can you please help me in doing that? I don't know anything in programming. ( c or python or c++)

  • I want to this question solution by programming c code. I need this solution as soon...

    I want to this question solution by programming c code. I need this solution as soon as possible i have to submit this code after 24 hours. please someone help this question thanks :D Programming Question: (15pts) Assume a finite number of resources of a single resource type must be managed. Processes may ask for a number of these resources and will return them once finished. If all resources are in use the request is denied and the process terminates....

  • Hi ! I need help please, I want to write java code, but that is difficult...

    Hi ! I need help please, I want to write java code, but that is difficult for me. it is about using annotation, reflection and XLM_ file. Please help me! I want explaintion with code and I want to se result please! My assignment is! Using the annotations and reflection API write an XML file exporter for composite objects of any kind. That is, the exporter should rely only on the annotations in the class definitions of the composite objects...

  • Note: This is the only question for this star and only the age range will change. Save and test your code in repl.it so you can paste it for credit in case you don't get it right on the first try....

    Note: This is the only question for this star and only the age range will change. Save and test your code in repl.it so you can paste it for credit in case you don't get it right on the first try. You are analyzing the results of a survey about the Internet and you want to know how often a specific age range of people use the Internet. You will be given a file containing a subset of the source...

  • I am in C++ programming, I need help with this assignments. The answer in this assignments...

    I am in C++ programming, I need help with this assignments. The answer in this assignments when I look for it it doesn't work in my visual studios. Can you please help me? I hardly have C in the class, if I fail I will fail the whole class and repeat this class again.   The file named Random.txt contains a long list of random numbers. Download the file to your system, then write a program that opens the file, reads...

  • I need a code/ script for this problem. I am new to programming and do not...

    I need a code/ script for this problem. I am new to programming and do not really know how to approach it, it may be a loop. There is a file containing info about grocery stores A, B, C, and D. The code would split/separate the info of grocery store A alone on 1 file (AS) and all other grocery stores in another file (O). I would like the python and Javascript version of this code please Thank you.

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT