Question

In: Computer Science

Following are the most important file management functions available in C. Use any 6 of them...

Following are the most important file management functions available in C. Use any 6 of them in your program and show the output.

Function

purpose

fopen ()

Creating a file or opening an existing file

fclose ()

Closing a file

fprintf ()

Writing a block of data to a file

fscanf ()

Reading a block data from a file

getc ()

Reads a single character from a file

putc ()

Writes a single character to a file

getw ()

Reads an integer from a file

putw ()

Writing an integer to a file

fseek ()

Sets the position of a file pointer to a specified location

ftell ()

Returns the current position of a file pointer

rewind ()

Sets the file pointer at the beginning of a file

Write the C code here and run it.

Output:

Can you type code please. Ty

Solutions

Expert Solution

code:-

#include <stdio.h>
 
int main ()
{
   char name [20];
   int age, length;
   FILE *fp;
   fp = fopen ("test.txt","w");
   fprintf (fp, "%s %d", "Ranaveer", 5);
   length = ftell(fp); // Cursor position is now at the end of file
   /* You can use fseek(fp, 0, SEEK_END); also to move the 
      cursor to the end of the file */
   rewind (fp); // It will move cursor position to the beginning of the file
   fscanf (fp, "%d", &age);
   fscanf (fp, "%s", name);
   fclose (fp);
   printf ("Name: %s \n Age: %d \n",name,age);
   printf ("Total number of characters in file is %d", length);
   return 0;
}

output:-

Name: Ranaveer
Age: 5
Total number of characters in file is 10

File:-

Ranaveer 5


Related Solutions

Write a C program that Reads a text file(any file)  and writes it to a binary file....
Write a C program that Reads a text file(any file)  and writes it to a binary file. Reads the binary file and converts it to a text file.
The following is a list of drugs. For this assignment, use any resources available to you...
The following is a list of drugs. For this assignment, use any resources available to you to find the structures and the pKa of these drugs. Identify the functional groups on each drug that will readily ionize under the appropriate pH conditions. Finally, determine the degree of ionization of the drug at physiological pH (7.4). MDMA Amphetamine Butalbital Hydrocodone Carisoprodol I understand how to find the functional groups. I need help understanding how to calculate the degree of ionization. With...
Describe short(!) th most important point of the following a Preferences, utility functions, and measures of...
Describe short(!) th most important point of the following a Preferences, utility functions, and measures of risk aversion. b Portfolio choice theory. c CAPM and APT. d The state-contingent claim model.
Complete the provided C++ program, by adding the following functions. Use prototypes and put your functions...
Complete the provided C++ program, by adding the following functions. Use prototypes and put your functions below main. 1. Write a function harmonicMeans that repeatedly asks the user for two int values until at least one of them is 0. For each pair, the function should calculate and display the harmonic mean of the numbers. The harmonic mean of the numbers is the inverse of the average of the inverses. The harmonic mean of x and y can be calculated...
Which of the following considerations is the most important one in the use of a vulnerability...
Which of the following considerations is the most important one in the use of a vulnerability scanning tool. a. Multiple functionalities cannot replace the importance of a scanner being kept current to the latest vulnerabilities. b. A vulnerability scanner is as good as the last time it was updated. c. The graphical user interface addresses ease of use rather than the effectiveness of the scanner. d. A vulnerability scanner does not need to have the ability to delete viruses.
Outline the objectives and functions of file systems management and the supported operations, including their reliability...
Outline the objectives and functions of file systems management and the supported operations, including their reliability and performance. Contrast different directory structures and create unique diagrams to illustrate an example of each directory structure (similar to Figures 10.9, 10.10, 10.11, 10.12, and 10.13 in your textbook). Insert these images as nodes of your concept map. To create your diagrams, you can choose to use a graphics editing software (PowerPoint, Paint, PhotoShop, etc.), an online mapping software tool (draw.io (Links to...
PLEASE ANSWER ALL OF THEM. Use the following file listing called intro.txt to answer the questions....
PLEASE ANSWER ALL OF THEM. Use the following file listing called intro.txt to answer the questions. Make sure to use regular expressions. Number your answers 1 through 7. The Unix operating system was pioneered by Ken Thompson and Dennis Ritchie at Bell Laboratories in the late 1960s. One of the primary goals in the design of the Unix system was to create an environment that promoted efficient program development. 1-Write the grep command to output all lines that begin with...
Assume the following functions have already been defined, write a main() using c++ that uses them...
Assume the following functions have already been defined, write a main() using c++ that uses them to fill a vector with random integers, remove the smallest and largest integers from the vector, save the result in a file called "trimmed.txt" void fillRandom(vector & nums, int howMany); // fill with specified number of integers int minValue(vector nums); // return smallest value in vector int maxValue(vector <;int> nums); // return largest value in vector void writeFile(string outFileName, vector nums ); // writes...
Students are to think about what is important to them in a job, ranking the following items, with 1 being the most important and 10 being the least important.
  Students are to think about what is important to them in a job, ranking the following items, with 1 being the most important and 10 being the least important. Tell me why you feel what is the most important (1, 2 and 3) and least important (8, 9, 10) to you - justify your answer. • Working Conditions • Quality of Coworkers/Mentors • Salary • Benefits • Location of Job • Level of Challenge/Responsibility • Training Programs Offered •...
Question 1 Which of the following is the most important reason for an organization to use...
Question 1 Which of the following is the most important reason for an organization to use enterprise risk management? To help an organization achieve its strategy through identifying, measuring, and managing the organization's most important risks and opportunities To ensure complete elimination of all risks that the organization may face To eliminate the possibility of the organization's present value of future cash flows being affected by exchange rate fluctuations To help an organization recover the costs incurred to determine whether...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT