Linux C Basics

Source: Internet
Author: User

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);

Related Article

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.