Foreword: After getting up this morning, I saw a system notification from the CSDN official assistant. I happened to have nothing to do, so I clicked to share my creative experience.
luming.02 , unknowingly today is the 128th day you have become a creator. To commemorate this day, we have prepared an exclusive surprise for you, and we look forward to your picking it up (valid for only 7 days! )
Opportunity
Talking about the original intention and opportunity to become a creator
Frankly speaking, my original intention was not pure. I didn’t just want to share experiences and exchange technology. Part of the reason was that this thing looked very cool. I thought that if I could have many fans on a certain Internet platform, I would be able to do so. There are related technologies, and I think this is really cool. I feel that this is a very useful and honorable thing.
But as I typed code and learned, I gradually felt the sense of recognition of sharing my skills and experience and being recognized by others. Just like playing a game and fighting BOSS, players gradually upgrade by fighting monsters. Upgrading your equipment, improving your skills and proficiency, and finally defeating the BOSS is of course a very fulfilling thing. It corresponds to your identity as a creator. You learn in the process of creating a blog and slowly improve. For myself, this is just like fighting a BOSS. I slowly feel that the process of improving myself is very fulfilling, and I can clearly feel the joy of improving my own skills. So in this process, I slowly determine myself. Definitely want to be a creator
In the future, creation and sharing will not stop, and most of them will focus on the following aspects:
- Sharing experience in practical projects
- Records in the daily learning process
- Technical communication through articles
- …
Harvest
Speaking of the gains in the process of writing this article, the biggest gains are actually from the technical side. From an ignorant novice to a novice with a little knowledge, I also know a lot more about the computer industry. I also gained a lot of learning methods. I also met many like-minded big guys and learned a lot from them. In short, these gains cannot be expressed in terms of quantity and material. Most of them are personal and all-round. promote
If we want to talk about how much we have gained from the data, it is probably as follows:
Daily life
Slowly, I wrote more and more blogs, shared more and more codes, and created more and more frequently. I gradually realized that creation has become a part of life. Now most of them have classes. If you don’t have classes, think about whether you have any creative ideas and inspirations. If you have them, you can think about how to create and write them. If you don’t have them, you might think about playing games or something. Generally speaking, it’s just a matter of limited time. With the energy of the school, he creates while studying at school.
Achievements
Speaking of the best code I’ve ever written, I don’t seem to have any good code, so here are two programs that can run completely, one is a three-piece chess game, and the other is an address book management system.
Three-piece chess
Header file
#define _CRT_SECURE_NO_WARNINGS 1 #include<stdio.h> #include<stdlib.h> #include<time.h> #define ROW 3 //Define behavior 3 #define COL 3 //Define column 3 //Print screen menu void screen(); //initialization void initialize(char board[ROW][COL], int row, int col); //Print the chessboard void displayboard(char board[ROW][COL],int row,int col); //Players play chess void palyer_move(char board[ROW][COL], int row, int col); //Computer plays chess void computer_move(char board[ROW][COL], int row, int col); //Judge winning or losing char IsWin(char board[ROW][COL], int row, int col);
Function implementation
#define _CRT_SECURE_NO_WARNINGS 1 #include"game.h" void screen() { printf("--------------------------\\ "); printf("---------1.Play ----------\\ "); printf("--------------------------\\ "); printf("---------2.Esc ----------\\ "); printf("--------------------------\\ "); } void initialize(char board[ROW][COL], int row, int col) { for (int i = 0; i < row; i + + ) { for (int j = 0; j < col; j + + ) { board[i][j] = ' '; } } } void displayboard(char board[ROW][COL], int row, int col) { for (int i = 0; i < row; i + + ) { for (int j = 0; j < col; j + + ) { printf(" %c ", board[i][j]); //Print split column if (j < col - 1) printf("|"); } //Print split lines if (i < row - 1) printf("\\ ---|---|---\\ "); } printf("\\ "); } void palyer_move(char board[ROW][COL], int row, int col) { int x = 0; int y = 0; printf("\\ ----Players play chess----\\ "); while (1) { printf("Please enter the coordinates of the move:"); scanf("%d %d", & amp;x, & amp;y); if (x <= 0 || x > 3 || y <= 0 || y > 3) { printf("Illegal input, please re-enter\\ "); } else if (board[x-1][y-1] == ' ') { board[x-1][y-1] = '*'; break; } else printf("The input position is occupied, please re-enter\\ "); } } void computer_move(char board[ROW][COL], int row, int col) { int x = 0; int y = 0; printf("\\ ----Computer playing chess----\\ "); while (1) { int x = rand() % ROW;//make the random number size 1--3 int y = rand() % COL;//make the random number size 1--3 if (board[x][y] == ' ') { board[x][y] = '#'; break; } } } static int IsFull(char board[ROW][COL], int row, int col) { int i = 0; int j = 0; for (i = 0; i < row; i + + ) { for (j = 0; j < col; j + + ) { if (board[i][j] == ' ') return 0; } } return 1; } //Player wins - '*' //Computer wins - '#' //Tie --- 'Q' //Game continues-'C' char IsWin(char board[ROW][COL], int row, int col) { int i = 0; for (i = 0; i < row; i + + ) { if (board[i][0] == board[i][1] & amp; & amp; board[i][1] == board[i][2] & amp; & amp; board[i] [0] != ' ') { return board[i][0]; } } for (i = 0; i < col; i + + ) { if (board[0][i] == board[1][i] & amp; & amp; board[1][i] == board[2][i] & amp; & amp; board[0] [i] != ' ') { return board[0][i]; } } if (board[0][0] == board[1][1] & amp; & amp; board[1][1] == board[2][2] & amp; & amp; board[1] [1] != ' ') { return board[1][1]; } if (board[0][2] == board[1][1] & amp; & amp; board[1][1] == board[2][0] & amp; & amp; board[1] [1] != ' ') { return board[1][1]; } //Judge a tie if (IsFull(board, row, col)) { return 'Q'; } return 'C'; }
Main function
#define _CRT_SECURE_NO_WARNINGS 1 #include"game.h" void game() { //Print the chessboard void screen(); char ret = 0; char board[ROW][COL] = { 0 }; initialize(board, ROW, COL);//Initialize the chessboard displayboard(board, ROW, COL);//Print the chessboard while (1) { palyer_move(board, ROW, COL);//Players play chess displayboard(board, ROW, COL);//Print the chessboard //Judge winning or losing ret = IsWin(board, ROW, COL); if (ret != 'C') { break; } computer_move(board, ROW, COL);//Computer playing chess displayboard(board, ROW, COL);//Print the chessboard //Judge winning or losing ret = IsWin(board, ROW, COL); if (ret != 'C') { break; } } if (ret == '*') { printf("Player wins\\ "); } else if (ret == '#') { printf("Computer wins\\ "); } else { printf("Tie\\ "); } } int main() { srand((unsigned int)time(NULL)); int input = 0; printf("Please enter to confirm whether to start the game\\ "); do { screen(); scanf("%d", & amp;input); switch(input) { case 1: printf("Start game\\ "); printf("Three pieces\\ "); game(); break; case 2: printf("Exit the game\\ "); break; default: printf("Illegal input, please re-enter\\ "); break; } } while (input != 2); return 0; }
Address book management system
Header file
#pragma once #include<stdio.h> #include<assert.h> #include<string.h> #include<stdlib.h> #define Name_Max 20 #define Tel_Number 12 #defineSex_Max 5 #defineAddress_Max 30 #define Contact_Max 100 #define Contact_SZ 3 //Contact structure typedef struct PeopleInformation { char name[Name_Max]; char telnumber[Tel_Number]; int age; char sex[Sex_Max]; char address[Address_Max]; }PeoInfor; //Address book structure typedef struct Contact { PeoInfor* data;//The structure array stores the contact structure int size;//Record how many contacts there are in the current address book int capacity;//Record the currently stored capacity }Contact; //Table of contents void menu(); //Initialize address book void InitContact(Contact* cp); //Add contact void AddContact(Contact* cp); //delete contact void DelContact(Contact* cp); //Find contacts by name int FindPeople(Contact* cp, char name[]); //Display all address book information void ShowContact(const Contact* cp); //Query contacts void SeachPeople(Contact* cp); //Modify contact information void ModifyContact(Contact* cp); //jia expansion void CheckContact(Contact* cp); //Destroy address book void DestoryContact(Contact* cp); //Generate a file and save the data in the address book void SaveContact(Contact* cp); //Read file information to address book void LoadContact(Contact* cp);
Function implementation
#define _CRT_SECURE_NO_WARNINGS 1 #include "Contact.h" void menu() { printf("\\ "); printf("--------------------------------\\ "); printf("--- 1.Add contact -----\\ "); printf("--- 2. Delete contact -----\\ "); printf("--- 3. Find contacts -----\\ "); printf("--- 4. Modify contact information -----\\ "); printf("--- 5. Display all information -----\\ "); printf("--- 0. Exit address book -----\\ "); printf("--------------------------------\\ "); } //Read file information to address book void LoadContact(Contact* cp) { \t//open a file FILE* pf = fopen("contact.txt", "rb"); if (pf == NULL) { perror("LoadContact"); return; } //read file PeoInfor temp = { 0 }; while (fread( & amp;temp, sizeof(PeoInfor), 1, pf)) { CheckContact(cp); cp->data[cp->size] = temp; cp->size + + ; } } //Initialize address book void InitContact(Contact* cp) { //Judge not empty assert(cp); //Initial initialization cp->size = 0; cp->capacity = Contact_SZ; cp->data = (PeoInfor*)calloc(cp->capacity, sizeof(PeoInfor)); if (cp->data == NULL) { perror("InitContact->calloc"); return; } //Read file information to address book LoadContact(cp); } //Check expansion void CheckContact(Contact* cp) { if (cp->size == cp->capacity) { PeoInfor* ptr = (PeoInfor*)realloc(cp->data, (cp->capacity + 2) * sizeof(PeoInfor)); if (ptr != NULL) { cp->data = ptr; cp->capacity + = 2; printf("Capacity expansion successful\\ "); } else { perror("AddContact->realloc"); return; } } } //Add contact void AddContact(Contact* cp) { //Judge not empty assert(cp); //Expand after judging full capacity CheckContact(cp); printf("Please enter the name of the contact you want to add:\\ "); scanf("%s", cp->data[cp->size].name); printf("Please enter the phone number of the contact you want to add:\\ "); scanf("%s", cp->data[cp->size].telnumber); printf("Please enter the age of the contact you want to add:\\ "); scanf("%d", & amp;(cp->data[cp->size].age)); printf("Please enter the gender of the contact you want to add:\\ "); scanf("%s", cp->data[cp->size].sex); printf("Please enter the address of the contact you want to add:\\ "); scanf("%s", cp->data[cp->size].address); cp->size + + ; printf("Added successfully\\ "); } //Find contacts by name int FindPeople(Contact* cp, char name[]) { assert(cp); for (int i = 0; i < cp->size; i + + ) { if (strcmp(cp->data[i].name, name) == 0) { return i; } } return -1; } //delete contact void DelContact(Contact* cp) { assert(cp); char name[Name_Max]; if (cp->size == 0) { printf("The address book is empty, no need to delete\\ "); return; } printf("Please enter the name of the contact you choose to delete:\\ "); scanf("%s", name); int ret = FindPeople(cp, name); if (ret == -1) { printf("The contact to be deleted does not exist\\ "); return; } for (int i = ret; i < cp->size - 1; i + + ) { cp->data[i] = cp->data[i + 1]; } cp->size--; printf("Deletion successful\\ "); } //Query contacts void SeachPeople(Contact* cp) { assert(cp); char name[Name_Max]; if (cp->size == 0) { printf("The address book is empty\\ "); return; } printf("Please enter the name of the contact selected to search:\\ "); scanf("%s", name); int ret = FindPeople(cp, name); if (ret == -1) { printf("The contact you are looking for does not exist\\ "); return; } //Name age gender phone address //xxx xxx xxx xxx xxx printf("%-10s%-5s%-5s%-12s%-30s\\ ", "name", "age", "gender", "phone", \ "address"); //Print personal information printf("%-10s%-5d%-5s%-12s%-30s\\ ", cp->data[ret].name, cp->data[ret].age, cp->data[ ret].sex, cp->data[ret].telnumber, cp->data[ret].address); } //Display all address book information void ShowContact(const Contact* cp) { assert(cp); if (cp->size == 0) { printf("The address book is empty\\ "); return; } //name age gender phone address //xxx xxx xxx xxx xxx printf("%-10s%-5s%-5s%-12s%-30s\\ ", "name", "age", "gender", "phone", \ "address"); for (int i = 0; i < cp->size; i + + ) { //Print everyone's information printf("%-10s%-5d%-5s%-12s%-30s\\ ", cp->data[i].name, cp->data[i].age, cp->data[ i].sex, cp->data[i].telnumber, cp->data[i].address); } } //Modify contact information void ModifyContact(Contact* cp) { assert(cp); char name[Name_Max]; if (cp->size == 0) { printf("The address book is empty\\ "); return; } printf("Please enter the name of the contact you choose to modify:\\ "); scanf("%s", name); int ret = FindPeople(cp, name); if (ret == -1) { printf("The contact information to be modified does not exist\\ "); return; } printf("Please enter the name of the contact you want to modify:\\ "); scanf("%s", cp->data[ret].name); printf("Please enter the phone number of the contact you want to modify: \\ "); scanf("%s", cp->data[ret].telnumber); printf("Please enter the age of the contact you want to modify:\\ "); scanf("%d", & amp;(cp->data[ret].age)); printf("Please enter the gender of the contact you want to modify:\\ "); scanf("%s", cp->data[ret].sex); printf("Please enter the address of the contact person to be modified: \\ "); scanf("%s", cp->data[ret].address); printf("Modification successful\\ "); } //Destroy address book void DestoryContact(Contact* cp) { free(cp->data); cp->data = NULL; cp->size = 0; cp->capacity = 0; } //Generate a file and save the data in the address book void SaveContact(Contact* cp) { \t//open a file FILE* pf = fopen("contact.txt", "wb"); if (pf == NULL) { perror("SaveContact"); return; } //write file for (int i = 0; i < cp->size; i + + ) { fwrite(cp->data + i, sizeof(PeoInfor), 1, pf); } //Close file fclose(pf); pf = NULL; }
Main function
#define _CRT_SECURE_NO_WARNINGS 1 #include "Contact.h" //Enumeration to increase the readability of the program enum options { EXIT, ADD, DEL, SEACH, MODIFY, SHOW }; int main() { int input = 0; //Create address book Contact con; //Initialize address book InitContact( & amp;con); do { menu(); printf("Please enter your choice: "); scanf("%d", & amp;input); switch(input) { //Add contact information case ADD: AddContact( & amp;con); break; //Delete contact information case DEL: DelContact( & amp;con); break; //Find information about a contact case SEACH: SeachPeople( & amp;con); break; //Modify a contact's information case MODIFY: ModifyContact( & amp;con); break; //Display the information of each contact in the address book case SHOW: ShowContact( & amp;con); break; //Exit the address book management system case EXIT: SaveContact( & amp;con); DestoryContact( & amp;con); printf("The address book has exited\\ "); break; //Prevent illegal input default: printf("Input error, please re-enter\\ "); break; } } while (input); return 0; }
Longing
In terms of creative planning, I hope to win the hearts of bloggers within this year, and then publish 30 articles within 3 months.
Of course, my career plan is to enter a big factory and get a decent job and salary. I hope that my gains will be worthy of my efforts, and I hope that I can make unlimited progress.
Tips
- The articles you publish will be displayed in the milestone area. You can also view the anniversary articles of other creators in the area.
- High-quality commemorative articles will receive mysterious rewards.