自打大学毕业后就没有再看过C,今天拿本c的书看了一点,温习下一些基础知识.
一, 一个在逆波兰运算中遇到的预读的函数.
#include <ctype.h>
#define NUMBER '0' /* signal that a number was found */
int getch(void);
void ungetch(int);
/* getop: get next character or numeric operand */
int getop(char s[])
{
int i, c;
while ((s[0] = c = getch()) == ' ' || c == '\t')
;
s[1] = '\0';
if (!isdigit(c) && c != '.')
return c; /* not a number */
i = 0;
if (isdigit(c)) /* collect integer part */
while (isdigit(s[++i] = c = getch()))
;
if (c == '.') /* collect fraction part */
while (isdigit(s[++i] = c = getch()))
;
s[i] = '\0';
if (c != EOF)
ungetch(c);
return NUMBER;
}
#define BUFSIZE 100
char buf[BUFSIZE]; /* buffer for ungetch */
int bufp = 0; /* next free position in buf */
int getch(void) /* get a (possibly pushed-back) character */
{
return (bufp > 0) ? buf[--bufp] : getchar();
}
void ungetch(int c) /* push character back on input */
{
if (bufp >= BUFSIZE)
printf("ungetch: too many characters\n");
else
buf[bufp++] = c;
}
二,拷贝字符串
/* strcpy: copy t to s; array subscript version */
void strcpy(char *s, char *t)
{
int i;
i = 0;
while ((s[i] = t[i]) != '\0')
i++;
}
/* strcpy: copy t to s; pointer version */
void strcpy(char *s, char *t)
{
int i;
i = 0;
while ((*s = *t) != '\0') {
s++;
t++;
}
}
/* strcpy: copy t to s; pointer version 2 */
void strcpy(char *s, char *t)
{
while ((*s++ = *t++) != '\0')
;
}
三,进栈,出栈
*p++ = val /*入栈*/
val = *--p /*出栈*/
分享到:
相关推荐
C语言中级教程 C语言回顾
C语言中级-1C语言回顾 C语言中级-1C语言回顾
SPT-02-实验00 C语言回顾.pptx
C回顾结构体及类型定义实用PPT课件.pptx
c的基础回顾 c语言的基础知识 复习巩固 基础知识 基础知识
C回顾结构体及类型定义实用PPT学习教案.pptx
C语言知识回顾 整理C语言知识 提高基础能力
c语言练习回顾
C语言相关知识点回顾
C语言知识点总结 考试复习、回顾知识点
C语言程序设计:回顾与总结.pdf
用于以后回顾复习查阅.zip 大学期间学习代码,包括C,Python,HTML等代码。用于以后回顾复习查阅.zip 大学期间学习代码,包括C,Python,HTML等代码。用于以后回顾复习查阅.zip 大学期间学习代码,包括C,Python,...
C语言基础笔记(回顾复习与自学跟进笔记)
挺好的资料,C语言的基本知识,通过本课 的学习,学员应该掌握如下知识: C语言概述 数据类型、运算符、表达式 程序的三种基本结构 复杂数据类型 文件
里面包括:c库函数,c语言回顾,vc++与msdn的使用,防错,函数设计等等!
C语言程序设计必要回顾(知识总结).pptx
6.1 数据的存储和基本数据类型 6.2 数据的输入和输出6.3 类型转换6.4 表达式C语言的基本数据类型有哪些?各种基本数据类型的常量有哪些表现形式?C语言有哪些表达式?各种表达式的求解规则是什么?
C语言是一种介于低级语言和高级语言之间的一种中级语言,它既 有低级语言(面向系统和硬件)的优点,又包含高级语言(面 向用户,容易记忆,易读性等)的优点。
C语言选择结构程序设计重点回顾终版.pdf
C语言的重点,需要英文备课、考试的同学们看过来吧