C # File read and write operations and file functions
int main ()
{
File* Fpcacl;
if ((Fpcacl=fopen ("C:1.txt", "w") = = null)
{
printf ("Open File Failure!n");
}
fprintf (Fpcacl, "1: = 0x%xn", (0x1u << 3) | (0xa5 << 24));
fprintf (Fpcacl, "2: = 0x%xn", (0x37 << 16) | (0x8 << 8) | (0x1u << 3) | (0x1u << 0));
fprintf (Fpcacl, "3: = 0x%xn", (0x37 << 16) | (0x8 << 8) | (0x1u << 3) | (0x1u << 0) | (0x1u << 24));
fprintf (Fpcacl, "4: = 0x%xn", (0x1u << 29) | (0x0f << 16) | (0x01 << 8) | 0X03);
fprintf (Fpcacl, "5: = 0x%xn", ((0x0u << 4) | ( 0x2u << 0)) & (~0x3u) | (0x1u << 0));
fprintf (Fpcacl, "6: = 0x%xn", (0x0u << 4) | ( 0x2u << 0));
Fclose (FPCACL);
printf ("1: = 0x%xn", (0x1u << 3) | (0xa5 << 24));
printf ("2: = 0x%xn", (0x37 << 16) | (0x8 << 8) | (0x1u << 3) | (0x1u << 0));
printf ("3: = 0x%xn", (0x37 << 16) | (0x8 << 8) | (0x1u << 3) | (0x1u << 0) | (0x1u << 24));
printf ("4: = 0x%xn", (0x1u << 29) | (0x0f << 16) | (0x01 << 8) | 0X03);
printf ("5: = 0x%xn", ((0x0u << 4) | ( 0x2u << 0)) & (~0x3u) | (0x1u << 0));
printf ("6: = 0x%xn", (0x0u << 4) | ( 0x2u << 0));
return 0;
}
Pieces turn off functions: fopen () and fclose () <file *fopen (char *filename, char *mode) | int fclose (file *fp) >
Character read-write functions: Fgetc () and FPUTC () <int fgetc (file *fp) |int fputc (int ch, file *fp) >
String read-write functions: Fgets () and fputs () <char *fgets (char *str, int num, file *fp) | int fputs (char *str, file *FP) >
Data block Read and write functions: Fread () and fwrite () <int fwrite (void *buf, int size, int count, file *fp) |int fread (void *buf, int size, int count, File *FP) >
Formatted read and write functions: fscanf () and Fprinf () <int fscanf (file *fp, char *format,...) | int fprintf (file *fp, char *format,...) >
Mode has the following morphological strings:
R opens a read-only file that must exist. The
r+ opens a read-write file that must exist.
W opens a write-only file, if the file exists, the file length is 0, that is, the file content disappears. If the file does not exist, the file is created. The
w+ opens a writable file, and if the file exists, the file length is zero, meaning that the file content disappears. If the file does not exist, the file is created.
A opens the write-only file in an additional way. If the file does not exist, the file will be created, and if the file exists, the written data will be added to the end of the file, that is, the original contents of the file will be retained. The
A + opens the writable file in an additional way. If the file does not exist, the file will be created, and if the file exists, the written data will be added to the end of the file, that is, the original contents of the file will be retained.
The above morphological strings can be added with a B character, such as RB, W+b, or ab+, and a B-character is added to tell the library to open the file as a binary file instead of a plain text file. However, in the POSIX system, including Linux ignores the character. The new file created by fopen () will have S_irusr|s_iwusr|s_irgrp|s_iwgrp|s_iroth|s_iwoth (0666) permissions, and this file permission will also refer to the Umask value