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

📄 lineholder.c

📁 String Pointers to explore how the pointer work
💻 C
字号:
/* lineholder.c- Bob Wilson  */#include <stdio.h>#include <string.h>#include "lineholder.h"void *malloc(int);void free(void*);static char *lines[MAXLINE];static int first, last, end, wrapped;void init_lineholder(int nlines){        if (nlines > MAXLINE)                nlines = MAXLINE;	first = last = 0;	end = nlines-1;	wrapped = 0;}void insert_line(char *line){	if (lines[last] != NULL)		free((void *) lines[last]);	if ((lines[last] =  (char * ) malloc(strlen(line) + 1)) != NULL)	   strcpy(lines[last], line);        last++;          if (last > end) {                last = 0;                   wrapped = 1;        }	if (wrapped)		first = (++first > end)? 0 : first;}void print_lines(void){        int i;        for (i = 0; i <= end; i++) {                if (lines[first] != NULL) {                        printf("%s", lines[first]);                        free ((void *) lines[first]);                        lines[first] = NULL;                }                first = (++first > end)? 0 : first;        }}

⌨️ 快捷键说明

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