C basic jobs

Source: Internet
Author: User

 

1. Range of different data types. Such as int char

6. Integer variable (INT): Short INTEGER (short INT) (-30 thousand ~ 30 thousand) (2 bytes), General INTEGER (INT) (-2.1 billion ~ + 2.1 billion) (4 bytes), long integer (there is no difference between this and ordinary integer ). It can be subdivided into signed and unsigned integer types. 7. floating point type variable (double) <indicates the number of fuzzy values>
Used to store real numbers
Specific type: Float (4 bytes) single precision (7 effective digits, 6 decimal places)
Double (8 bytes) (16 effective digits, 15 decimal places)
Long double (12 bytes) long dual-precision

A ~ Z: 65 ~ 90 ~ Z: 97 ~ 122 '0 '~ '9': 48 ~ 57

 

Classroom assignment: receives any value input by the user, and the bit to be set to 0 (the number of the binary digits,), and outputs the calculation result.
01110110 the starting position of the number of 5th bits is 0th bits
11011111 bitwise AND 00100000
00000001 the value cannot be bit-wise (OR)
01010110

 

Job 1: calculate the maximum common number of two integers. (The most efficient algorithm) // 8, and the maximum number of 4 common appointments is 4
Job 2: judge whether an integer is a prime number.
// The number that can only be divisible by 1 is a prime number.

Two principles for Project Creation:
Professionalism is embodied in details. Handle error details!
The user is a naughty kid! Robust code and fault tolerance!

Job (small project): implement a search function that refers to the find_str sub-string. If the sub-string is found, replace the sub-string in the target string with the specified desc_str, for example: find def in abcdefg, replace it with Def, and the entire string becomes: abcdefg.

If the specified substring is not found,-1 is returned. Otherwise, a value corresponding to the first character found in the string obj_str is returned.
Int strreplace (char obj_str [], char find_str [], char desc_str [])
// Char STR [50] = "abcdefg ";
// Int Pos = strreplace (STR, "def", "defffffa ");
// Basic requirements: implement equal-length replacement
// Advanced requirement: Implement unequal replacement (memory operation function)
// Ignore whether the space of obj_str is sufficient.

 

Select a job: Use the variable parameter technology to accumulate the values of each variable parameter Member, display the equation, and print the accumulated result value.

Homework: implement the function of the tower, which will be stacked from a small ring to a large ring. (a small ring can be placed on the top of a large ring, and a ring smaller than it can be placed on the bottom of a small ring) the algorithm for moving from one location to another, and provides only one buffer location (three locations as a whole ). Print the process of moving the specific ring (the ring number) (for example, the output of the text list: Where to move the ring number. Which position of the ring to be moved. ..), N is larger than N-1.

Int main (INT argc, char * argv [])

_ Stdc _ If _ stdc _ has been defined, if the compiler uses GCC to compile the code, this macro will be 1, if it is compiled with G ++ or other, it is not 1.

 

Homework: implement a micro-MIS (Information Management System) and save QQ Personal Data (name, QQ number, and gender ). Users can enter personal information of Q friends to display all Q friends data items (a certain number of Q friends data items ).
Use an automatic dynamic structure array or dynamically allocate the heap capacity:
Unsigned Total = 0;
Struct student * pstu = NULL;
While (...) {
... // Receives user input Q-You Information
Struct student TMP = {...}; // Add User input to the initialization project respectively
Struct student * tmpstu = pstu;
Pstu = (struct student *) malloc (++ total * sizeof (struct student ));
Memcpy (pstu, tmpstu, sizeof (total-1) * sizeof (struct student ));
Memcpy (pstu + total, & TMP, sizeof (TMP ));
If (null! = Tmpstu) {free (tmpstu); tmpstu = NULL ;}
// Ask whether the user still needs to enter
}
// Practical significance: data can be stored with the number of unknown elements.

 

 

Job: Use the structure of the last job (qq-related) to dynamically implement it. Add a QQ member profile member (the length is not fixed, but the maximum number is exceeded ). It is required that the dynamic compression structure (network packet transmission) be used up as much space as possible.
# Include <stdio. h>
// Structure in work:
Typedef struct
{
// Add other members
Long SIZE; // count the length of the Personal Profile's dynamic heap Space
Char * introduce; // Personal Profile MAX: 500 k
} Working_data; // structure definition in the process
Void temp = malloc (size); // dynamic allocation cannot exceed the upper limit of the structure's intruduce members
Data * Data = (data) temp;
Memcpy (data-> introduce. STR, size );

Client/Server local structure (write the structure to the hard disk ):
Typedef struct
{
// Add other members
Long SIZE; // count the length of the Personal Profile's dynamic heap Space
Char introduce [500*1024]; // personal profile; max: 500 kb cannot be written into the hard disk by using pointer members. It must be a long member space. Why cannot I Use Pointer members?
} Local_data; // structure definition in the process

 

 

 

 

 

 

 

 

 

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.