Access functions in the C language

Source: Internet
Author: User

int   Access (const   char   *filename,   int   amode), Amode parameter is 0, indicates the existence of the check file, If the file exists, returns 0, does not exist, returns -1

This function can also check other file attributes:
06 Checking Read and Write permissions
04 Checking Read Permissions
02 Checking Write permissions
01 Checking Execution Permissions
00 checking the existence of files
And this even if the file does not have Read permission, you can also determine whether the file exists in the
There is a return of 0, there is no return-1

_mkdir functions under Windows

#include <direct.h>intconstchar *dirname);
Parameter: DirName is the path name of the directory that returns the value of the pointer:If the new directory is created, each of these features returns a value of 0. in error, the function returns –1 mode_t parameters of mkdir function under Linux
#include <sys/stat.h>int mkdir (constchar *path, mode_t mode);
Parameter: path is directory name mode is a directory permission return value: Return 0 indicates success, return 1 indicates an error, and the errno value is set. the use of the sprintf () function in C language 1. The function is contained in the header file of the stdio.h.
2, sprintf and usually our usual function of printf function is very similar. The sprintf function prints to the string, and the printf function prints the output to the screen. The sprintf function is widely used in our operations to convert other data types into string types.
int sprintf (charconstchar *format, ...).

In addition to the first two parameters, the optional parameter can be any one. Buffer is the name of the character array; format is a formatted string

The function is to format the string, as follows:

(1) Converts a numeric variable to a string.

(2) Get 16 binary and 8 binary strings of integer variables.

(3) Concatenate multiple strings.

 1     Charstr[ the] = {0 }; 2     intdata =1024x768; 3     //convert data to a string 4sprintf (str,"%d", data); 5     //get hex of data 6sprintf (str,"0x%X", data); 7     //get the octal of data 8sprintf (str,"0%o", data); 9     Const Char*S1 ="Hello";Ten     Const Char*S2 =" World"; One     //connection strings S1 and S2 A 

fopen () is a common function used to open a file in a specified manner, with the following prototype:
FILE * fopen (const char * path, const char * mode);

"Parameter" path is the file name that contains the path, mode is the file open mode.

Fwrite is a C-language function that points to a file to write a data block.

size_t fwrite (constvoid* buffer, size_t size, size_t count, file* Stream);
Note: This function operates in binary form and is not limited to text file return values: Returns the number of data blocks actually written (1) buffer: is a pointer to the address of the data for Fwrite, (2) Size: The single-byte number to write the content, and (3) Count: The number of data items to write to the size byte, (4) stream: Target file pointer, (5) returns the number of data items actually written to count.

Attention

  (1) The stream fclose () must be closed after the write operation Fwrite ().

(2) without closing the stream, each time the data is read or written, the file pointer will point to the next pointer to the location of the data to be written or read.

void * ptr, size_t size, size_t count, FILE * stream);

Where PTR: A pointer to the saved result; Size: The sizes of each data type; count: the number of data; stream: File pointer

The function returns the number of read data.

Access functions in the C language

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.