Question
Problem: Write a small C program to open a binary file using user provided file name to write to it. Write only the even numbers
Problem: Write a small C program to open a binary file using user provided file name to write to it. Write only the even numbers from 0 to 100 to the file.
Hints:
1. Use library functions fptr = fopen(filename, "wb") to open the binary file to write to.
2. Use printf("prompt") to prompt the use for the file name
3. Use scanf("%s", filename) to read the file name from the user
4. Check whether the file was open successfully.
5. Use a loop to write only even numbers from0 to 100 to the file:
a. Use modulus operation to find the even numbers
b. Use fprintf(fptr, "%d ",evenNumber) to write to the file
6. close the file using fclose(fptr)
7. Compile and run the program on your virtual machine.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started