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
Get step-by-step solutions from verified subject matter experts
