⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ipl.cpp

📁 Atheon is a portable Server/Client program designed for easy incorporation into just about any game
💻 CPP
字号:
#include <fstream.h>
#include <stdlib.h>
#include <iostream.h>
#include <iomanip.h>
#include <string.h>
#include <conio.c>

char filename[25]="";
int temp=1;

struct info_node {
char serial[16];
info_node *next;
};

info_node *head;
info_node *current;

void insert_node(info_node *new_rec_ptr);
info_node *position_insertion_point(in_addr serial[16]);
void make_node_new_head(info_node *new_rec_ptr);
void add_node_to_end(info_node *new_rec_ptr);
void move_current_to_end();
void delete_head_of_list();
void delete_end_of_list(info_node *previous_ptr);
void delete_from_middle_of_list(info_node *previous_ptr);
int verify_delete();
void delete_node(info_node *previous);
void write_list_to_file();

void add_record(char serial[16]) {
info_node *new_rec_ptr;

new_rec_ptr = new info_node;

if(new_rec_ptr != NULL) {
new_rec_ptr->serial;

insert_node(new_rec_ptr);
}
else {
cout<<"WARNING: Memory error.  New record cannot be added."<<endl;
}
write_list_to_file();
}

void insert_node(info_node *new_rec_ptr) {
info_node *before;
info_node *after;

if(head == NULL) {
new_rec_ptr->next = NULL;
head = new_rec_ptr;
}
else {
if(strcmp(new_rec_ptr->serial, head->serial) < 0) {
make_node_new_head(new_rec_ptr);
}
else {
current = position_insertion_point(new_rec_ptr->serial[16]);
before = current;
after = current->next;

if(after == NULL) {
add_node_to_end(new_rec_ptr);
}
else {
before->next = new_rec_ptr;
new_rec_ptr->next = after;
}
}
}
}

info_node *position_insertion_point(char serial[16]) {
char temp_serial[16];
info_node *temp;
int tempint;

if(head->next != NULL) {
current = head;
temp = current->next;
strcpy(serial, temp->serial);
tempint = strcmp(serial, temp_serial);
while((tempint > 0) && (current->next != NULL)) {
current = temp;
temp = current->next;
strcpy(temp_serial, temp->serial);
tempint = strcmp(serial, temp_serial);
}
}
else {
current = head;
}
return(current);
}

void make_node_new_head(info_node *new_rec_ptr) {
info_node *temp;
temp = head;
new_rec_ptr->next = temp;
head = new_rec_ptr;
}

void add_node_to_end(info_node *new_rec_ptr) {
new_rec_ptr->next = NULL;

move_current_to_end();
current->next = new_rec_ptr;
}

void move_current_to_end() {
current = head;
while(current->next != NULL) {
current = current->next;
}
}

char getallips() {
current=head;
while(current != NULL) {
current=current->next;
return current->serial[16];     // might overlap ips so that server only recieves last ip from IPL
}
}

/*int numberofips() {
current=head;
int number=0;
do {
if(current!=NULL) {
number++;
}
current=current->next;
}while(current!=NULL);
return number;
}              */

void display_list() {
char fullname[36];

clrscr();
current = head;
if(current != NULL) {
cout<<endl;
cout<<"IP"<<endl;
cout<<"----------------"<<endl;
do {
cout<<current->serial<<endl;
current = current->next;
}while(current != NULL);
system("pause");
}
else {
cout<<"NO RECORDS TO DISPLAY."<<endl;
system("pause");
}
}

void delete_record(in_addr temp_serial[16]) {
info_node *previous;

clrscr();
previous = NULL;
current = head;

while(strcmp(current->serial, temp_serial) != 0 && current != NULL) {
previous = current;
current = current->next;
}

if(current != NULL) {
cout<<"IP FOUND"<<endl;
cout<<"IP: "<<current->serial<<endl;
if(verify_delete()) {
cout<<"IP REMOVED."<<endl;
}
else {
cout<<"IP NOT REMOVED."<<endl;
}
}
else {
cout<<"NO MATCH FOUND."<<endl;
}
}

int verify_delete() {
return 1;
}

void delete_node(info_node *previous) {
if(current == head) {
delete_head_of_list();
}
else {
if(current->next == NULL) {
delete_end_of_list(previous);
}
else {
delete_from_middle_of_list(previous);
}
}
}

void delete_head_of_list() {
current = head;
if(head->next != NULL) {
head = current->next;
}
else {
head = NULL;
}
delete current;
}

void delete_end_of_list(info_node *previous) {
delete current;
previous->next = NULL;
current = head;
}

void delete_from_middle_of_list(info_node *previous) {
previous->next = current->next;
delete current;
current = head;
}

void delete_list() {
info_node *temp;
current = head;
do {
temp = current->next;

delete current;
current = temp;
}while(temp != NULL);
}

void write_list_to_file() {
ofstream outfile;

outfile.open("IPL.dtb", ios::out);
if(outfile) {
current = head;
if(head != NULL) {
do {
outfile<<current->serial<<endl;
current = current->next;
}while(current != NULL);
}

outfile<<"END OF FILE"<<endl;
outfile.close();
}
else {
cout<<"Error opening file."<<endl;
}
}

void create_file() {
ofstream outdata;

outdata.open("IPL.dtb", ios::app);
if(outdata) {
current = head;
if(head != NULL) {
do {
outdata<<current->serial<<endl;
current = current->next;
}while(current != NULL);
}
}
else {
cout<<"Error opening file."<<endl;
}
outdata<<"END OF FILE"<<endl;
outdata.close();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -