In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces how to realize the port management of the background management of the switch, which has a certain reference value. Interested friends can refer to it. I hope you will gain a lot after reading this article. Let the editor take you to know about it.
10 switch background management port management project requirements switch
Port:
1) Port name
2) Port statu
3) IP address of the port
4) Port Typ
WAN
LAN
Project realization
1. Add menu frame
# include # include # include FILE * file; void init (void) {/ / Open the file file = fopen ("users.txt", "r"); if (! file) {/ / equivalent to file = = NULL printf ("File opening failed"); / / return 1; exit (1);}} void login (void) {char name [32]; char password [16]; char line [128] Char name_tmp [32]; char password_tmp [16]; char * ret; / / enter user name and password while (1) {system ("cls"); / / enter user name and password printf ("Please enter user name:"); scanf ("% s", name); printf ("Please enter password:") Scanf ("% s", password); / / read the account from the file and make a judgment! While (1) {/ / read one line ret = fgets (line, sizeof (line), file); / / line: "admin 123456\ n" if (! ret) {break;} sscanf (line, "% s% s", name_tmp, password_tmp) If (! strcmp (name, name_tmp) & &! strcmp (password, password_tmp)) {break;}} if (ret) {/ / username and password match succeeded break;} else {printf ("wrong username or password!\ n"); system ("pause") System ("cls"); fseek (file, 0, SEEK_SET); / / set the location pointer inside the file to the header} void create_user (void) {system ("cls"); printf ("\ n\ nWhat-create account--\ n\ n"); printf ("to be implemented.\ n\ n") Printf ("press any key to return to the main menu"); fflush (stdin); getchar ();} void ip_admin (void) {system ("cls"); printf ("\ n\ n---IP management--\ n\ n"); printf ("to be implemented.\ n\ n"); printf ("press any key to return to the main menu"); fflush (stdin); getchar () } void logout (void) {system ("cls"); fclose (file); exit (0);} void input_error (void) {system ("cls"); printf ("\ n\ ninput error! \ n\ n "); printf ("\ n\ nPlease re-enter\ n\ n "after pressing any key); fflush (stdin); getchar ();} void show_memu (void) {system (" cls "); / / print function menu printf ("-switch background management -\ n "); printf (" 1. Create account\ n); printf ("2. IP Management\ n"); printf ("3. Exit\ n "); printf (" 4. Port Management\ n "); printf (" Please choose: ");} void show_ports (void) {system (" cls "); printf ("-- Port status -\ n "); printf (" to be implemented.\ n "); system (" pause ");} void set_ports (void) {system (" cls "); printf ("-Port setting -\ n ") Printf ("to be implemented.\ n"); system ("pause");} void port_admin (void) {char n; while (1) {system ("cls"); printf ("1. View port\ n "); printf (" 2. Set port\ n "); printf (" 3. Return to the main menu\ n "); printf (" Please select: "); fflush (stdin); scanf ("% c ", & n); if (n = ='1') {show_ports ();} else if (n = ='2') {set_ports ();} else if (n = ='3') {break } else {input_error ();} int main (void) {char n; / / menu number selected by the user init (); / / initialize login (); / / Log in to while (1) {show_memu (); fflush (stdin); scanf ("% c", & n) Switch (n) {case'1: create_user (); break; case'2: ip_admin (); break; case'3: logout (); break; case'4: port_admin (); break Default: input_error (); break;}} return 0;}
two。 Representation of port information
Add type definitions and port variables
Struct port {char name [16]; / / name of the port int status; / / 1: activate 0: disable char ip [16]; / / 192.168.1.5 char type [4]; / / port type LAN WAN}; / / 5 port variables struct port port1;struct port port2;struct port port3;struct port port4;struct port port5 are defined
Project realization
Void show_port (struct port port) {printf ("name [% s]\ t status [% s]\ tIP [% s]\ t type [% s]\ n", port.name, port.status = = 0? "disable": "activate", port.ip, port.type);} void show_ports (void) {system ("cls"); printf ("--Port status--\ n"); printf ("PORT1:\ t"); show_port (port1); printf ("PORT2:\ t"); show_port (port2); printf ("PORT3:\ t"); show_port (port3) Printf ("PORT4:\ t"); show_port (port4); system ("pause");} void set_port1 (void) {system ("cls"); printf ("--set PORT1 port -\ n"); printf ("Please enter port name:"); scanf ("% s", port1.name); printf ("Please enter port status: [0: disable] [1: activate]") Scanf ("% d", & port1.status); printf ("Please enter port type: [LAN or WAN]"); scanf ("% s", port1.type); printf ("Please enter IP address of port:"); scanf ("% s", port1.ip); system ("pause");} void set_port2 (void) {system ("cls") Printf ("--set PORT2 port -\ n"); printf ("Please enter port name:"); scanf ("% s", port2.name); printf ("Please enter port status: [0: prohibit] [1: activate]"); scanf ("% d", & port2.status); printf ("Please enter port type: [LAN or WAN]") Scanf ("% s", port2.type); printf ("Please enter the IP address of the port:"); scanf ("% s", port2.ip);} void set_port3 (void) {system ("cls"); printf ("--set PORT3 port -\ n"); printf ("Please enter port name:"); scanf ("% s", port3.name) Printf ("Please enter Port status: [0: disable] [1: activation]"); scanf ("% d", & port3.status); printf ("Please enter Port Type: [LAN or WAN]"); scanf ("% s", port3.type); printf ("Please enter IP address of Port:"); scanf ("% s", port3.ip) } void set_port4 (void) {system ("cls"); printf ("--set PORT4 port -\ n"); printf ("Please enter port name:"); scanf ("% s", port4.name); printf ("Please enter port status: [0: disable] [1: activate]"); scanf ("% d", & port4.status) Printf ("Please enter port type: [LAN or WAN]"); scanf ("% s", port4.type); printf ("Please enter IP address of port:"); scanf ("% s", port4.ip);} void set_port5 (void) {system ("cls"); printf ("--set PORT5 port -\ n"); printf ("Please enter port name:") Scanf (% s ", port5.name); printf (" Please enter port status: [0: disable] [1: activate] "); scanf ("% d ", & port5.status); printf (" Please enter port type: [LAN or WAN] "); scanf ("% s ", port5.type); printf (" Please enter port IP address: "); scanf ("% s ", port5.ip) } void set_ports (void) {char n; while (1) {system ("cls"); printf ("--Port setting -\ n"); printf ("1. PORT1\ n"); printf ("2. PORT2\ n"); printf ("3. PORT3\ n"); printf ("4. PORT4\ n"); printf ("5. PORT5\ n") Printf ("6. Return\ n "); printf (" Please select: "); fflush (stdin); scanf ("% c ", & n); switch (n) {case'1: set_port1 (); break; case'2: set_port2 (); break Case'3: set_port3 (); break; case'4: set_port4 (); break; case'5: set_port5 (); break; case'6: return; default: input_error (); break Project elaboration
1. Why use "structure" (structure)
However, when you need to represent some replication information, it is not convenient to use simple data types.
For example: student information (student number, name, class, telephone number, age)
two。 What is "structure"?
Structure is a "data type" defined by programmers.
Is a new "data type" that is composed of multiple basic data types, or other structures.
3. Definition of structure
Struct structure name {
Member type member name
Member type member name
}
Example:
Struct student {char name [16]; int age; char tel [12];}; Special attention:
1) start with struct
2) finally, use a semicolon
3) members are separated by semicolons
4. Initialization of structure
Demo
# include struct student {char name [16]; int age;}; int main (void) {struct student S1 = {"Rock", 38}; struct student S2 = {.age = 100,.name = "Zhang Sanfeng"}; struct student S3; s3.age = 40; strcpy (s3.name, "Yang Guo"); printf ("% s,% d\ n", s1.name, s1.age) Printf ("% s,% d\ n", s2.name, s2.age); printf ("% s,% d\ n", s3.name, s3.age); return 0;} 5. The use of structures / / define structure variables / / Note: the complete type name is struct student / / and not just studentstruct student S1, S2, struct, student, s1.name, scanf ("% s", s1.name); s1.name = 25; S2 = S1; / / values can be assigned directly between structure variables.
Form of use:
Structural body variable. Member variable
Use it in the middle. Separation
6. Use structure as function parameter # include # include struct student {char name [16]; int age; char tel [12];}; void work (struct student stu) {stu.age++; printf ("% s struct student stu% d\ n", stu.name, stu.age);} int main (void) {struct student s; strcpy (s.name, "Rock"); s.age = 38; work (s) / / the structure variable s, as a function parameter, does not change the value of s itself, printf ("% s _ 1% d\ n", s.name, s.age); return 0;}
Note:
It is generally not recommended to use the structure directly as a function parameter.
Because the size of the structure is relatively large, direct transmission, consumption of performance!
Solution (using pointers)
7. Global variables, local variables
Test1.c
# include void east_travel (void); char master [16] = "Nu WA"; void west_travel (void) {char master [16] = "Tang Monk"; printf ("[Journey to the West] Boss is% s\ n", master);} int main (void) {char master [16] = "Tathagata Buddha"; printf ("[main] Boss is:% s\ n", master); char c; printf ("do you enter the daughter's country?" (y or N)\ n "); fflush (stdin); scanf ("% c ", & c); if (cased daughter Y' | | caged daughter Y') {char master [16] =" Queen "; printf (" [main- daughter country] boss is:% s\ n ", master);} printf (" [main] boss is:% s\ n ", master); east_travel (); return 0;}
Test2.c
# include extern char master [16]; / / failed to initialize! Indicates that this global variable is defined in another file! Void east_travel (void) {printf ("[Journey to the East] boss is:% s\ n", master);}
Gcc test1.c test2.c
Project activity exercise 1
Implement project 10 independently
Exercise 2
1. Define a structure that describes the basic information of a game character.
The role information includes: name, gender, force value.
And ask the user to enter 1 role.
The running effect is as follows:
Reference Code:
# include struct role {char name [32]; char sex; / / 'male: female int power;}; int main (void) {struct role R1, R2; printf ("Please enter the name of the role:"); scanf ("% s", r1.name); fflush (stdin); printf ("Please enter the gender of the role:"); scanf ("% c", & r1.sex) Printf ("Please enter character's force value:"); scanf ("% d", & r1.power); printf ("\ nskill = role setting =\ n"); printf ("name:% s\ n", r1.name); printf ("gender:% c\ n", r1.sex); printf ("force value:% d\ n", r1.power); return 0 } Thank you for reading this article carefully. I hope the article "ccontroller + how to realize the port management of switch background management" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support and pay attention to the industry information channel. More related knowledge is waiting for you to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.