文件输入输出
#include<stdio.h>
#include<string.h>
void split(char* buff) {
if (buff == NULL)
return;
char* token;
token = strtok(buff, "=");
while (token != NULL) {
printf("%s\n", token);
token = strtok(NULL, "=");
}
}
int main() {
char writebuff[40], readbuff[40];
FILE* fp = NULL;
fp = fopen("C:\\Users\\15333\\Desktop\\rw.txt", "w+");
printf("请根据提示,写入保存到文件中的内容!\n");
printf("ppp_name=");
scanf("%s", writebuff);
fprintf(fp, "ppp_name=%s\n", writebuff);
printf("ppp_passwd=");
scanf("%s", writebuff);
fprintf(fp, "ppp_passwd=%s\n", writebuff);
printf("time_out=");
scanf("%s", writebuff);
fprintf(fp, "time_out=%s\n", writebuff);
printf("dns=");
scanf("%s", writebuff);
fprintf(fp, "dns=%s\n", writebuff);
printf("ip=");
scanf("%s", writebuff);
fprintf(fp, "ip=%s\n", writebuff);
rewind(fp);
while (fgets(readbuff, 40, fp) != NULL) {
split(readbuff);
}
fclose(fp);
return 0;
}
双向链表
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
typedef struct line {
struct line* pre;
int data;
struct line* next;
}line;
line* initline(line* head);
line* insertline(line* head, int data, int add);
line* delline(line* head, int data);
void display(line* head);
line* changeline(line* head, int data, int newdata);
int main() {
line* head = NULL;
head = initline(head);
display(head);
head = insertline(head, 4, 4);
display(head);
head = delline(head, 4);
display(head);
head = changeline(head, 3, 5);
display(head);
return 0;
}
line* initline(line* head)
{
head = (line*)malloc(sizeof(line));
head->pre = NULL;
head->next = NULL;
head->data = 1;
line* list = head;
for (int i = 2; i <= 3; i++) {
line* body = (line*)malloc(sizeof(line));
body->pre = NULL;
body->next = NULL;
body->data = i;
list->next = body;
body->pre = list;
list = body;
}
return head;
}
line* insertline(line* head, int data, int add) {
line* temp = (line*)malloc(sizeof(line));
temp->data = data;
temp->pre = NULL;
temp->next = NULL;
if (add == 1) {
temp->next = head;
head->pre = temp;
temp = head;
}
else {
line* body = head;
for (int i = 2; i < add; i++) {
body = body->next;
}
if (body->next == NULL) {
body->next = temp;
temp->pre = body;
}
else {
body->next->pre = temp;
temp->next = body->next;
body->next = temp;
temp->pre = body;
}
}
return head;
}
line* delline(line* head, int data) {
line* temp = head;
while (temp) {
if (temp->data == data) {
if (temp->next == NULL) {
temp->pre->next = NULL;
free(temp);
return head;
}
temp->pre->next = temp->next;
temp->next->pre = temp->pre;
free(temp);
return head;
}
temp = temp->next;
}
printf("链表中无该数据元素");
return head;
}
void display(line* head) {
line* temp = head;
while (temp) {
if (temp->next == NULL) {
printf("%d\n", temp->data);
}
else {
printf("%d->", temp->data);
}
temp = temp->next;
}
}
line* changeline(line* head, int data, int newdata) {
line* temp = head;
while (temp) {
if (temp->data == data) {
temp->data = newdata;
return head;
}
temp = temp->next;
}
printf("链表中无该数据元素");
return head;
}