10marks: 1.what Are The Various Data Types in C?Explain
10marks: 1.what Are The Various Data Types in C?Explain
int age;
char letter;
Arrays Arrays are sequences of data items having homogeneous values. They have adjacent memory
Pointers These are powerful C features which are used to access the memory and deal with their addres
Union These allow storing various data types in the same memory location. Pro
union with different members, but only a single member can contain a va
used for
1. Opening/Creating a file
2. Closing a file
3. Reading a file
4. Writing in a file
Let us see the syntax for each of the above operations in a table:
FILE *fp;
fp=fopen (“filename”, ”‘mode”);
Where,
fp – file pointer to the data type “FILE”.
filename – the actual file name with full path of the file.
mode – refers to the operation that will be performed on the file. Example: r,
w, a, r+, w+ and a+. Please refer below the description for these mode of
operations.
Declaration: int fclose(FILE *fp);
fclose() – To fclose() function closes the file that is being pointed by file pointer fp. In a C
close a file program, we close a file as below.
fclose (fp);
fgets function is used to read a file line by line. In a C program, we use fgets
function as below.
fgets (buffer, size, fp);
where,
buffer – buffer to put the data in.
fgets() – To size – size of the buffer
fp – file pointer
read a file
Declaration:
int fprintf(FILE *fp, const char *format, …);fprintf() function writes
string into a file pointed by fp. In a C program, we write string into a file as
below.
fprintf() – To fprintf (fp, “some data”); or
write into a file fprintf (fp, “text %d”, variable_name);
r – Opens a file in read mode and sets pointer to the first character in the file. It returns null if file
does not exist.
w – Opens a file in write mode. It returns null if file could not be opened. If file exists, data are
overwritten.
a – Opens a file in append mode. It returns null if file couldn’t be opened.
r+ – Opens a file for read and write mode and sets pointer to the first character in the file.
w+ – opens a file for read and write mode and sets pointer to the first character in the file.
a+ – Opens a file for read and write mode and sets pointer to the first character in the file. But, it
can’t modify existing contents.