Linux C Basics
I. Basic data and functions
Int, Char, float, double
(1) format input and output
Scanf () // read the keyboard
Printf () // % d, % C, % s, % F
(2) Single Input/output character
Getchar ()
Putchar ()
Instance:
Int num;
Scanf ("% d", & num );
Printf ("num = % d", num );
Char;
A = getchar ();
Putchar ();
Ii. String
Strlen
Strcpy
Strcmp
Strcat
The difference between a string and a character array is that there is an empty character '\ 0' at the end of the string to end the string.
When reading a string using the scanf () Statement, spaces are not allowed in the input.
The gets () and puts () functions are used for the input and output of strings respectively.
Iii. Structure
Struct name {
...
};
Typedef definition type
Typedef int Myint;
Iv. File Operations
Fopen (if the opened file is in the current directory, the path can be omitted. Otherwise, the file name with a path is used. Note that escape characters '\' are used between directories at different levels '\\', you cannot use '\'. After opening the file, you must determine the return value and check whether the file is opened. Other operations can be continued only when the file is opened)
Fclose
Fflush clear stream
Fputc character output
Fgetc Character Input
Feof file ended
Fgets string Input
Fputs string output
Fread field input
Fwrite Field Output
Fprintf
Rewind File Location
Fseek (read/write location of a mobile file Stream)
Ftell (returns the current read/write location of the file stream)
Fgetpos, fsetpos, lseek
Ferror
Clearerr
Setbuf clears the stream
Instance:
char filename[] = "/Users/kllmctrl/Desktop/HelloC/HelloC/test.txt"; FILE *fp; if((fp=fopen(filename,"w"))==NULL) { printf("cannot open this file\n"); exit(0); } fclose(fp);