Question

Please provide the required libraries,structures and data fields needed to open and read files. These files...

Please provide the required libraries,structures and data fields needed to open and read files.

These files are made in C programming language on ubantu running linux OS.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

1.Required Header files are
stdio.h is used to call the built-in function(fopen,fclose
stdlib.h
example
#include <stdio.h>
#include <stdlib.h>
___________________________________
2. FILE(available in stdio.h) type pointer
Example FILE *fp;
you need a pointer which can point your file.
it means that with help of this pointer you can track your
file, this pointer allows you to manage your file such as opening,
reading, and writing data to/and from a file.
FILE is a structure data type(built-in):
it holds information of file such as size of file and so on.
3. NULL(it is a macro available in both stdio.h and stdlib.h) and fopen(built in function, it is used to open the file.)
fopen() returns FILE pointer if file is open successfully
otherwise it will return NULL pointer, it means file could not be open.
NULL pointer means no valid memory address assigned.
Example:-
FILE *fp;
fp = fopen(filename, "r");//"r" means read mode
if (fp == NULL)
{
printf("Cannot open file \n");
exit(0);
}
4. EOF(macro available in stdio.h)
it is used to detect the end of file character.
so you should read file till the end.
there is EOF character at the end of file.
and should stop the reading if reached at the end of file.

5. fclose(built in function, it is used to close the file.)
Example:-
ch = fgetc(fp);
while (ch != EOF)
{
printf ("%c", ch);
ch = fgetc(fp);
}
difference between macro and function
___________________________________________
when function is called, control goes to the body of the function.
after the execution of body control returns back to the normal sequence
so, it time consuming process(to send control some where else)

when macro is used a copy is inserted in the program's memory
so there is no need to send control anywhere.
that's why macro is faster than function.

but macro consumes more memory(due to it's insertion in program's memory) in comparison of function.
function takes less memory.

you can put all the above things together to make a useful program.

Add a comment
Know the answer?
Add Answer to:
Please provide the required libraries,structures and data fields needed to open and read files. These files...
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
  • Programming Assignment 1 Structures, arrays of structures, functions, header files, multiple code files Program description: Read...

    Programming Assignment 1 Structures, arrays of structures, functions, header files, multiple code files Program description: Read and process a file containing customer purchase data for books. The books available for purchase will be read from a separate data file. Process the customer sales and produce a report of the sales and the remaining book inventory. You are to read a data file (customerList.txt, provided) containing customer book purchasing data. Create a structure to contain the information. The structure will contain...

  • Write a python program to handle data from/to files (open, read/write, delete to handle data). It...

    Write a python program to handle data from/to files (open, read/write, delete to handle data). It uses exception handling – try and except to catch and handle exceptions.

  • Create a class named Horse that contains data fields for the name, color, and birth year....

    Create a class named Horse that contains data fields for the name, color, and birth year. Include get and set methods for these fields. Next, create a subclass named RaceHorse, which contains an additional field that holds the number of races in which the horse has competed and additional methods to get and set the new field. Write an application that demonstrates using objects of each class. Save the files as Horse.java, RaceHorse.java, and DemoHorses.java. Program 1 Submission Template Fields:...

  • You are required to open a file for input and read the data in that file...

    You are required to open a file for input and read the data in that file into an array (named data). Use the variable size to count how many elements in the file. Create the file yourself in notepad and call it data.txt so that it has the following numbers in order: 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 Please help with this. In C please

  • This is for open data structures C++ 1. Read the entire input one line at a...

    This is for open data structures C++ 1. Read the entire input one line at a time. Then output all lines sorted by length, with the shortest lines first. In the case where two lines have the same length, resolve their order using the usual “sorted order.” Duplicate lines should be printed only once.

  • UNIX/LINUX: Read the man page for tcpdump and provide the command and accompanying options required to...

    UNIX/LINUX: Read the man page for tcpdump and provide the command and accompanying options required to read the file named /tmp/tcpdump.dmp, suppress name resolution (avoid DNS lookups), and print each packet in both hex and ASCII. Please only respond if you know the answer.

  • Question 1 (50) MapReduce For each problem, provide test data (as input files), MapReduce programs, and...

    Question 1 (50) MapReduce For each problem, provide test data (as input files), MapReduce programs, and running results (screen shoots) on Hadoop i) Write a program to read input file (an integer number per line) and remove duplicated numbers ii) When data are transmitted from map to reduce, <key, value will be automatically sorted in an ascending order. Write a program that can read input file (an integer number per line) and write them out in a descending order.

  • Question 2 In this question, you will read two data files that include integers into two...

    Question 2 In this question, you will read two data files that include integers into two different arrays – the same way we did in class (but we are doing to arrays here). Duplicates are ok. 1- After you read the data into the array (use one function that takes an int array and a dsize by reference just like we did in class, and call that from main to fill both arrays). 2- Include a printArray function so that...

  • Learn how to use the advanced data structures (such as: list, tuple, string, dictionary, and set)...

    Learn how to use the advanced data structures (such as: list, tuple, string, dictionary, and set) ·         Learn and practice how to use functions. ·         Learn and practice how to use file I/Os. ·         Appreciate the importance of data validations. ·         Provide appropriate documentation and good programming style. Python Programming Description of the problem: Write a “censor” program that first reads a file with “bad words” such as “sex”, “drug”, “rape”, “kill”, and so on, places them in a set, and then reads an...

  • 3. Draw the structures of each of the following molecules and then provide the reagents needed...

    3. Draw the structures of each of the following molecules and then provide the reagents needed to convert each of the given starting materials into the required pro a) dimethyl sulfide dimethyl sulfoxide b) phenol methyl phenyl ether c) dimethyl ketone 2-propanol ㅡㅡ

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
ADVERTISEMENT