The C programming language (second edition,KR) exercise(CHAPTER 4)

      E x c e r c i s e 4 − 1 Excercise\quad 4-1 Excercise41

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
int strindex(char s[],char t[]);
int strrindex(char s[],char t[]);int main(void) 
{char s[100]="qwoulddfsdfdsgdsgdsgdsouldasdasdasd";char t[100]="ould";	int l_index=strindex(s,t);int r_index=strrindex(s,t);	printf("l_index=%d\n",l_index);	printf("r_index=%d\n",r_index);		return 0;
}int strindex(char s[],char t[])
{int i,j,k;for(i=0;s[i]!='\0' ;i++){for(j=i,k=0;t[k]!='\0' && s[j]==t[k];j++,k++);if((k>0)&&(t[k]=='\0'))return i;}		return -1;
}int strrindex(char s[],char t[])
{int i,j,k;int t_len=strlen(t);int s_len=strlen(s);if(t_len>s_len){return -1;				}else{for(i=s_len-t_len;i>=0 ;i--){for(j=i,k=0;t[k]!='\0' && s[j]==t[k];j++,k++);if((k>0)&&(t[k]=='\0'))return i;	    	}		return -1;}
}

      E x c e r c i s e 4 − 2 Excercise\quad 4-2 Excercise42:输出如图1所示。

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>double atof_myself(char s[]);int main(void) 
{char s1[100]="123.789e1";char s2[100]="123456123456.789e-10";	char s3[100]="123.789";		double d1=atof_myself(s1);double d2=atof_myself(s2);double d3=atof_myself(s3);	printf("d1=%lf\n",d1);printf("d2=%lf\n",d2);	printf("d3=%lf\n",d3);		return 0;
}double atof_myself(char s[])
{double val,power,power_more;int i,sign,sign_more,power_more_index;for(i=0;isspace(s[i]);i++);sign=(s[i]=='-')? -1:1;if((s[i]=='-')||(s[i]=='+')){i++;}	for(val=0.0;isdigit(s[i]);i++){val=10.0*val+(s[i]-'0');		}	if(s[i]=='.'){i++;}for(power=1.0;isdigit(s[i]);i++){val=10.0*val+(s[i]-'0');power *=10.0;		}	if((s[i]=='e') ||(s[i]=='E')){i++;sign_more=(s[i]=='-')? -1:1;if((s[i]=='-')||(s[i]=='+')){i++;}	for(power_more_index=0;isdigit(s[i]);i++){power_more_index=10*power_more_index+(s[i]-'0');	}power_more=1.0;for(i=0;i<power_more_index;i++){power_more=power_more*10.0;			}	if(sign_more==-1){return ((sign * val/power)/power_more);    	    		    	}else{return ((sign * val/power)*power_more);  	}		}else{return (sign * val/power); 	   	}	
}
图1.

      E x c e r c i s e 4 − 3 Excercise\quad 4-3 Excercise43

#include <stdio.h>
#include <stdlib.h>   /* for atof() */
#include <math.h>     /* for fmod() */#define MAXOP 100     /* max size of operand or operator */
#define NUMBER '0'    /* signal that a number was found */int getop(char []);
void push(double);
double pop(void);/* reverse Polish calculator */
int main()
{int type;double op2;char s[MAXOP];while ((type = getop(s)) != EOF) {switch (type) {case NUMBER:push(atof(s));break;case '+':push(pop() + pop());break;case '*':push(pop() * pop());break;case '-':op2 = pop();push(pop() - op2);break;case '/':op2 = pop();if (op2 != 0.0)push(pop() / op2);elseprintf("error: zero divisor\n");break;case '%':op2 = pop();if (op2 != 0.0)push(fmod(pop(),op2));elseprintf("error: zero divisor\n");break;case '\n':printf("\t%.8g\n", pop());break;				 default:printf("error: unknown command %s\n", s);break;}}return 0;
}#define MAXVAL 100   /* maximum depth of val stack */
int sp = 0;          /* next free stack position */
double val[MAXVAL];  /* value stack *//* push: push f onto value stack */
void push(double f)
{if (sp < MAXVAL)val[sp++] = f;elseprintf("error: stack full, can't push %g\n", f);
}/* pop: pop and return top value from stack */
double pop(void)
{if (sp > 0)return val[--sp];else {printf("error: stack empty\n");return 0.0;}
}#include <ctype.h>
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 != '.' && c != '-'){	return c; /* not a number */}if(c == '-'){i = 0;			c = getch();	s[++i] = c;			}else{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);}if (i == 1 && s[0] == '-') // if s[0] == '-' && s[1] == '\0', return minus operatorreturn '-';	return NUMBER;
}#define BUFSIZE 100char 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");elsebuf[bufp++] = c;
}

      E x c e r c i s e 4 − 4 Excercise\quad 4-4 Excercise44

#include <stdio.h>
#include <stdlib.h>   /* for atof() */
#include <math.h>     /* for fmod() */#define MAXOP 100     /* max size of operand or operator */
#define NUMBER '0'    /* signal that a number was found */int getop(char []);
void push(double);
double pop(void);
void showTop(void);
void duplicate(void);
void swapItems(void);
void clearStack();/* reverse Polish calculator */
int main()
{int type;double op2;char s[MAXOP];while ((type = getop(s)) != EOF) {switch (type) {case NUMBER:push(atof(s));break;case '+':push(pop() + pop());break;case '*':push(pop() * pop());break;case '-':op2 = pop();push(pop() - op2);break;case '/':op2 = pop();if (op2 != 0.0)push(pop() / op2);elseprintf("error: zero divisor\n");break;case '%':op2 = pop();if (op2 != 0.0)push(fmod(pop(),op2));elseprintf("error: zero divisor\n");break;
/****************************************************/				 case '?':showTop();break;case '#':duplicate();break;case '~':swapItems();break;case '!':clearStack();	break;				
/****************************************************/				 case '\n':printf("\t%.8g\n", pop());break;				 default:printf("error: unknown command %s\n", s);break;}}return 0;
}#define MAXVAL 100   /* maximum depth of val stack */
int sp = 0;          /* next free stack position */
double val[MAXVAL];  /* value stack *//* push: push f onto value stack */
void push(double f)
{if (sp < MAXVAL)val[sp++] = f;elseprintf("error: stack full, can't push %g\n", f);
}/* pop: pop and return top value from stack */
double pop(void)
{if (sp > 0)return val[--sp];else {printf("error: stack empty\n");return 0.0;}
}/**********************************************************/
void showTop(void)
{if(sp > 0)printf("Top of stack contains: %8g\n", val[sp-1]);elseprintf("The stack is empty!\n");
}void duplicate(void)
{double temp = 0.0;	if(sp > 0){temp = pop();push(temp);push(temp);				}elseprintf("The stack is empty!\n");	}void swapItems(void)
{double item1 = 0.0;double item2 = 0.0;	if(sp >= 2){item1 = pop();item2 = pop();push(item1);push(item2);			}elseprintf("The stack is empty!\n");	
}/* pop only returns a value if sp is greater than zero. So setting the
stack pointer to zero will cause pop to return its error */void clearStack(void)
{sp = 0;
}/**********************************************************/#include <ctype.h>
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 != '.' && c != '-'){	return c; /* not a number */}if(c == '-'){i = 0;			c = getch();	s[++i] = c;			}else{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);// }if (i == 1 && s[0] == '-') // if s[0] == '-' && s[1] == '\0', return minus operatorreturn '-';	return NUMBER;
}#define BUFSIZE 100char 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");elsebuf[bufp++] = c;
}

      E x c e r c i s e 4 − 5 Excercise\quad 4-5 Excercise45

#include <stdio.h>
#include <stdlib.h>  
#include <math.h>   #define MAXOP 100     /* max size of operand or operator */
#define NUMBER '0'    /* signal that a number was found */int getop(char []);
void push(double);
double pop(void);
void showTop(void);
void duplicate(void);
void swapItems(void);
void clearStack();/* reverse Polish calculator */
int main()
{int type;double op2;char s[MAXOP];while ((type = getop(s)) != EOF) {switch (type) {case NUMBER:push(atof(s));break;case '+':push(pop() + pop());break;case '*':push(pop() * pop());break;case '-':op2 = pop();push(pop() - op2);break;case '/':op2 = pop();if (op2 != 0.0)push(pop() / op2);elseprintf("error: zero divisor\n");break;case '%':op2 = pop();if (op2 != 0.0)push(fmod(pop(),op2));elseprintf("error: zero divisor\n");break;
/****************************************************/				 case '?':showTop();break;case '#':duplicate();break;case '~':swapItems();break;case '!':clearStack();	break;				
/****************************************************/
/****************************************************/				 case '$':push(sin(pop()));break;case '@':push(exp(pop()));break;case '^':op2 = pop();push(pow(pop(),op2));break;				
/****************************************************/				 case '\n':printf("\t%.8g\n", pop());break;				 default:printf("error: unknown command %s\n", s);break;}}return 0;
}#define MAXVAL 100   /* maximum depth of val stack */
int sp = 0;          /* next free stack position */
double val[MAXVAL];  /* value stack *//* push: push f onto value stack */
void push(double f)
{if (sp < MAXVAL)val[sp++] = f;elseprintf("error: stack full, can't push %g\n", f);
}/* pop: pop and return top value from stack */
double pop(void)
{if (sp > 0)return val[--sp];else {printf("error: stack empty\n");return 0.0;}
}/**********************************************************/
void showTop(void)
{if(sp > 0)printf("Top of stack contains: %8g\n", val[sp-1]);elseprintf("The stack is empty!\n");
}void duplicate(void)
{double temp = 0.0;	if(sp > 0){temp = pop();push(temp);push(temp);				}elseprintf("The stack is empty!\n");	}void swapItems(void)
{double item1 = 0.0;double item2 = 0.0;	if(sp >= 2){item1 = pop();item2 = pop();push(item1);push(item2);			}elseprintf("The stack is empty!\n");	
}/* pop only returns a value if sp is greater than zero. So setting the
stack pointer to zero will cause pop to return its error */void clearStack(void)
{sp = 0;
}/**********************************************************/#include <ctype.h>
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 != '.' && c != '-'){	return c; /* not a number */}if(c == '-'){i = 0;			c = getch();	s[++i] = c;			}else{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);// }if (i == 1 && s[0] == '-') // if s[0] == '-' && s[1] == '\0', return minus operatorreturn '-';	return NUMBER;
}#define BUFSIZE 100char 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");elsebuf[bufp++] = c;
}

      E x c e r c i s e 4 − 6 Excercise\quad 4-6 Excercise46:其实这一题的意图似乎还是很模糊的,我这里的做法是提供26个变量(分别对应26个小写英文字母),然后再提供一个数组用来存储这26个变量的值。如果要对某个变量赋值可以类似 x = n n n . n n n x=nnn.nnn x=nnn.nnn来操作,其中 x x x表示26个小写英文字母中的任何一个, n n n . n n n nnn.nnn nnn.nnn表示即将赋值给变量的值,这个值可以为负数,负数的话在最前面需要加上 − - ,比如 − n n n . n n n -nnn.nnn nnn.nnn。某个变量在参与运算之前需要先进行赋值操作,否则可能拿到的是默认值 0.0 0.0 0.0,变量参加运算的一个例子为 a 8 + a8+ a8+实际是变量 a a a的值和8进行加法运算。这里还记录了最近赋值或参与运算的是那个变量,并且 _ \_ _符号对应的命令操作会将这个最近赋值或参与运算的变量以及对应的值打印出来。

#include <stdio.h>
#include <stdlib.h> 
#include <ctype.h>
#include <math.h>
#include <string.h> #define MAXOP     100     /* max size of operand or operator */
#define NUMBER    '0'     /* signal that a number was found */
#define SETVARIABLE 's'   /* signal that a variable is being assigned */
#define GETVARIABLE 'g'   /* signal that a variable is being retrieved */
#define NUMVARS 26        /* number of variables supported (a-z) */enum boolean {FALSE, TRUE};int getop(char []);
void push(double);
double pop(void);
void showTop(void);
void duplicate(void);
void swapItems(void);
void clearStack();
void view_stack();	/* initially as space such that malformed use of '=' won't cause segfaults */
char last_recent = ' '; 
/* array to store the double values for variables. 
Supports variables a through z (lower case). Initial value is 0*/
double varVals[NUMVARS] = {0.0}; /* reverse Polish calculator */
int main()
{int type;double op2;char s[MAXOP];while ((type = getop(s)) != EOF) {switch (type) {case NUMBER:push(atof(s));break;
/****************************************************/				 case SETVARIABLE:if (strlen(s) > 2 && s[1] == '='){int v = s[0];           /* stores variable */int i = 1;              /* start at 1 since while loop needed ++i for a few reasons */while (s[++i] != '\0')  /* this removes the variable name= part of s e.g. if s == "a=123.45" after loop s == "123.45" */s[i - 2] = s[i];    /* shifts chars two to the left by 2 */s[i - 2] = '\0';        /* since '\0' isn't copied, terminate string manually */varVals[v - 'a'] = atof(s); /* convert string to double and store it in array */}elseprintf("error: set variable length too small or incorrectly formatted (%s)\n", s);break;case GETVARIABLE:push(varVals[s[0] - 'a']);  /* convert the variable name to stored value */break;	
/****************************************************/				 case '+':push(pop() + pop());break;case '*':push(pop() * pop());break;case '-':op2 = pop();push(pop() - op2);break;case '/':op2 = pop();if (op2 != 0.0)push(pop() / op2);elseprintf("error: zero divisor\n");break;case '%':op2 = pop();if (op2 != 0.0)push(fmod(pop(),op2));elseprintf("error: zero divisor\n");break;
/****************************************************/				 case '?':showTop();break;case '#':duplicate();break;case '~':swapItems();break;case '!':clearStack();	break;				
/****************************************************/case '$':push(sin(pop()));break;case '@':push(exp(pop()));break;case '^':op2 = pop();push(pow(pop(),op2));break;									// case '\n':// printf("\t%.8g\n", pop());// break;case '\n':view_stack();break;	case '_':printf("The last recently used variable is %c=%8g\n",last_recent, varVals[last_recent-'a']);break;					 default:printf("error: unknown command %s\n", s);break;}}return 0;
}#define MAXVAL 100   /* maximum depth of val stack */
int sp = 0;          /* next free stack position */
double val[MAXVAL];  /* value stack *//* push: push f onto value stack */
void push(double f)
{if (sp < MAXVAL)val[sp++] = f;elseprintf("error: stack full, can't push %g\n", f);
}/* pop: pop and return top value from stack */
double pop(void)
{if (sp > 0)return val[--sp];else {printf("error: stack empty\n");return 0.0;}
}/* push: push f onto value stack */
void view_stack()
{int i=sp;if (sp >0){while(i>0){printf("view_stack:%8g\n",val[i-1]);i=i-1;}}elseprintf("view_stack:Stack is empty\n");
}/**********************************************************/
void showTop(void)
{if(sp > 0)printf("Top of stack contains: %8g\n", val[sp-1]);elseprintf("The stack is empty!\n");
}void duplicate(void)
{double temp = 0.0;	if((sp > 0) &&(sp < MAXVAL)){temp = pop();push(temp);push(temp);				}elseprintf("The stack is empty!\n");	}void swapItems(void)
{double item1 = 0.0;double item2 = 0.0;	if(sp >= 2){item1 = pop();item2 = pop();push(item1);push(item2);			}elseprintf("The stack is empty!\n");	
}/* pop only returns a value if sp is greater than zero. So setting the
stack pointer to zero will cause pop to return its error */void clearStack(void)
{sp = 0;
}/**********************************************************/#include <ctype.h>
int getch(void);
void ungetch(int);/* getop: get next character or numeric operand */
int getop(char s[])
{int i, c;char setVar = FALSE;i = 0;while ((s[0] = c = getch()) == ' ' || c == '\t');s[1] = '\0';if (!isdigit(c) && !isalpha(c) && c != '.' && c != '-'){	return c; /* not a number */}if (c >= 'a' && c <= 'z'){last_recent=c;
/* get next char and check if it was an equal symbol.*/ 		if ((s[++i] = c = getch()) == '='){			setVar = TRUE;c = getch();s[++i] = c;		}else{if (c != EOF){		ungetch(c);}return GETVARIABLE;}}if(c == '-'){		c = getch();	s[++i] = c;			}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);}
/* if s[0] == '-' && s[1] == '\0', return minus operator */	if (i == 1 && s[0] == '-') return '-';	if (setVar){	return SETVARIABLE;	}		return NUMBER;
}#define BUFSIZE 100char 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");elsebuf[bufp++] = c;
}

      E x c e r c i s e 4 − 7 Excercise\quad 4-7 Excercise47

#include <stdio.h>
#include <stdlib.h> 
#include <ctype.h>
#include <math.h>
#include <string.h> #define MAXOP     100     /* max size of operand or operator */
#define NUMBER    '0'     /* signal that a number was found */
#define SETVARIABLE 's'   /* signal that a variable is being assigned */
#define GETVARIABLE 'g'   /* signal that a variable is being retrieved */
#define NUMVARS 26        /* number of variables supported (a-z) */enum boolean {FALSE, TRUE};int getop(char []);
void push(double);
double pop(void);
void showTop(void);
void duplicate(void);
void swapItems(void);
void clearStack();
void view_stack();	/* initially as space such that malformed use of '=' won't cause segfaults */
char last_recent = ' '; 
/* array to store the double values for variables. 
Supports variables a through z (lower case). Initial value is 0*/
double varVals[NUMVARS] = {0.0}; /* reverse Polish calculator */
int main()
{int type;double op2;char s[MAXOP];while ((type = getop(s)) != EOF) {switch (type) {case NUMBER:push(atof(s));break;
/****************************************************/				 case SETVARIABLE:if (strlen(s) > 2 && s[1] == '='){int v = s[0];           /* stores variable */int i = 1;              /* start at 1 since while loop needed ++i for a few reasons */while (s[++i] != '\0')  /* this removes the variable name= part of s e.g. if s == "a=123.45" after loop s == "123.45" */s[i - 2] = s[i];    /* shifts chars two to the left by 2 */s[i - 2] = '\0';        /* since '\0' isn't copied, terminate string manually */varVals[v - 'a'] = atof(s); /* convert string to double and store it in array */}elseprintf("error: set variable length too small or incorrectly formatted (%s)\n", s);break;case GETVARIABLE:push(varVals[s[0] - 'a']);  /* convert the variable name to stored value */break;	
/****************************************************/				 case '+':push(pop() + pop());break;case '*':push(pop() * pop());break;case '-':op2 = pop();push(pop() - op2);break;case '/':op2 = pop();if (op2 != 0.0)push(pop() / op2);elseprintf("error: zero divisor\n");break;case '%':op2 = pop();if (op2 != 0.0)push(fmod(pop(),op2));elseprintf("error: zero divisor\n");break;
/****************************************************/				 case '?':showTop();break;case '#':duplicate();break;case '~':swapItems();break;case '!':clearStack();	break;				
/****************************************************/case '$':push(sin(pop()));break;case '@':push(exp(pop()));break;case '^':op2 = pop();push(pow(pop(),op2));break;									// case '\n':// printf("\t%.8g\n", pop());// break;case '\n':view_stack();break;	case '_':printf("The last recently used variable is %c=%8g\n",last_recent, varVals[last_recent-'a']);break;					 default:printf("error: unknown command %s\n", s);break;}}return 0;
}#define MAXVAL 100   /* maximum depth of val stack */
int sp = 0;          /* next free stack position */
double val[MAXVAL];  /* value stack *//* push: push f onto value stack */
void push(double f)
{if (sp < MAXVAL)val[sp++] = f;elseprintf("error: stack full, can't push %g\n", f);
}/* pop: pop and return top value from stack */
double pop(void)
{if (sp > 0)return val[--sp];else {printf("error: stack empty\n");return 0.0;}
}/* push: push f onto value stack */
void view_stack()
{int i=sp;if (sp >0){while(i>0){printf("view_stack:%8g\n",val[i-1]);i=i-1;}}elseprintf("view_stack:Stack is empty\n");
}/**********************************************************/
void showTop(void)
{if(sp > 0)printf("Top of stack contains: %8g\n", val[sp-1]);elseprintf("The stack is empty!\n");
}void duplicate(void)
{double temp = 0.0;	if((sp > 0) &&(sp < MAXVAL)){temp = pop();push(temp);push(temp);				}elseprintf("The stack is empty!\n");	}void swapItems(void)
{double item1 = 0.0;double item2 = 0.0;	if(sp >= 2){item1 = pop();item2 = pop();push(item1);push(item2);			}elseprintf("The stack is empty!\n");	
}/* pop only returns a value if sp is greater than zero. So setting the
stack pointer to zero will cause pop to return its error */void clearStack(void)
{sp = 0;
}/**********************************************************/#include <ctype.h>
int getch(void);
void ungetch(int);/* getop: get next character or numeric operand */
int getop(char s[])
{int i, c;char setVar = FALSE;i = 0;while ((s[0] = c = getch()) == ' ' || c == '\t');s[1] = '\0';if (!isdigit(c) && !isalpha(c) && c != '.' && c != '-'){	return c; /* not a number */}if (c >= 'a' && c <= 'z'){last_recent=c;
/* get next char and check if it was an equal symbol.*/ 		if ((s[++i] = c = getch()) == '='){			setVar = TRUE;c = getch();s[++i] = c;		}else{if (c != EOF){		ungetch(c);}return GETVARIABLE;}}if(c == '-'){		c = getch();	s[++i] = c;			}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);}
/* if s[0] == '-' && s[1] == '\0', return minus operator */	if (i == 1 && s[0] == '-') return '-';	if (setVar){	return SETVARIABLE;	}		return NUMBER;
}#define BUFSIZE 100char 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");elsebuf[bufp++] = c;
}/*ungets() actually takes a little bit of thought.  Should thefirst character in "s" be sent to ungetch() first, or shouldit be sent last?  I assumed that most code calling getch()would be of this form:char array[...];int i;   while (...) {array[i++] = getch();}                  In such cases, the same code might call ungets() as:ungets(array);and expect to repeat the while loop to get the same stringback.  This requires that the last character be sent firstto ungetch() first, because getch() and ungetch() work with a stack.     To answer K&R2's additional question for this problem,it's usually preferable for something like ungets() to justbuild itself on top of ungetch().  This allows us to change ungetch() and getch() in the future, perhaps to use a linked list instead, without affecting ungets().
*/ 
void ungets(const char *s)
{    int i, len;len = strlen(s);if(BUFSIZE - bufp >= len)  // ungets() must do its own bounds checking{for(i = strlen(s) - 1; i >= 0; i--)ungetch(s[i]);}elseprintf("error: insufficient space in buffer, can't execute ungets()\n");
}

      E x c e r c i s e 4 − 8 Excercise\quad 4-8 Excercise48

#include <stdio.h>
#include <stdlib.h> 
#include <ctype.h>
#include <math.h>
#include <string.h> #define MAXOP     100     /* max size of operand or operator */
#define NUMBER    '0'     /* signal that a number was found */
#define SETVARIABLE 's'   /* signal that a variable is being assigned */
#define GETVARIABLE 'g'   /* signal that a variable is being retrieved */
#define NUMVARS 26        /* number of variables supported (a-z) */enum boolean {FALSE, TRUE};int getop(char []);
void push(double);
double pop(void);
void showTop(void);
void duplicate(void);
void swapItems(void);
void clearStack();
void view_stack();	/* initially as space such that malformed use of '=' won't cause segfaults */
char last_recent = ' '; 
/* array to store the double values for variables. 
Supports variables a through z (lower case). Initial value is 0*/
double varVals[NUMVARS] = {0.0}; /* reverse Polish calculator */
int main()
{int type;double op2;char s[MAXOP];while ((type = getop(s)) != EOF) {switch (type) {case NUMBER:push(atof(s));break;
/****************************************************/				 case SETVARIABLE:if (strlen(s) > 2 && s[1] == '='){int v = s[0];           /* stores variable */int i = 1;              /* start at 1 since while loop needed ++i for a few reasons */while (s[++i] != '\0')  /* this removes the variable name= part of s e.g. if s == "a=123.45" after loop s == "123.45" */s[i - 2] = s[i];    /* shifts chars two to the left by 2 */s[i - 2] = '\0';        /* since '\0' isn't copied, terminate string manually */varVals[v - 'a'] = atof(s); /* convert string to double and store it in array */}elseprintf("error: set variable length too small or incorrectly formatted (%s)\n", s);break;case GETVARIABLE:push(varVals[s[0] - 'a']);  /* convert the variable name to stored value */break;	
/****************************************************/				 case '+':push(pop() + pop());break;case '*':push(pop() * pop());break;case '-':op2 = pop();push(pop() - op2);break;case '/':op2 = pop();if (op2 != 0.0)push(pop() / op2);elseprintf("error: zero divisor\n");break;case '%':op2 = pop();if (op2 != 0.0)push(fmod(pop(),op2));elseprintf("error: zero divisor\n");break;
/****************************************************/				 case '?':showTop();break;case '#':duplicate();break;case '~':swapItems();break;case '!':clearStack();	break;				
/****************************************************/case '$':push(sin(pop()));break;case '@':push(exp(pop()));break;case '^':op2 = pop();push(pow(pop(),op2));break;									// case '\n':// printf("\t%.8g\n", pop());// break;case '\n':view_stack();break;	case '_':printf("The last recently used variable is %c=%8g\n",last_recent, varVals[last_recent-'a']);break;					 default:printf("error: unknown command %s\n", s);break;}}return 0;
}#define MAXVAL 100   /* maximum depth of val stack */
int sp = 0;          /* next free stack position */
double val[MAXVAL];  /* value stack *//* push: push f onto value stack */
void push(double f)
{if (sp < MAXVAL)val[sp++] = f;elseprintf("error: stack full, can't push %g\n", f);
}/* pop: pop and return top value from stack */
double pop(void)
{if (sp > 0)return val[--sp];else {printf("error: stack empty\n");return 0.0;}
}/* push: push f onto value stack */
void view_stack()
{int i=sp;if (sp >0){while(i>0){printf("view_stack:%8g\n",val[i-1]);i=i-1;}}elseprintf("view_stack:Stack is empty\n");
}/**********************************************************/
void showTop(void)
{if(sp > 0)printf("Top of stack contains: %8g\n", val[sp-1]);elseprintf("The stack is empty!\n");
}void duplicate(void)
{double temp = 0.0;	if((sp > 0) &&(sp < MAXVAL)){temp = pop();push(temp);push(temp);				}elseprintf("The stack is empty!\n");	}void swapItems(void)
{double item1 = 0.0;double item2 = 0.0;	if(sp >= 2){item1 = pop();item2 = pop();push(item1);push(item2);			}elseprintf("The stack is empty!\n");	
}/* pop only returns a value if sp is greater than zero. So setting the
stack pointer to zero will cause pop to return its error */void clearStack(void)
{sp = 0;
}/**********************************************************/#include <ctype.h>
int getch(void);
void ungetch(int);/* getop: get next character or numeric operand */
int getop(char s[])
{int i, c;char setVar = FALSE;i = 0;while ((s[0] = c = getch()) == ' ' || c == '\t');s[1] = '\0';if (!isdigit(c) && !isalpha(c) && c != '.' && c != '-'){	return c; /* not a number */}if (c >= 'a' && c <= 'z'){last_recent=c;
/* get next char and check if it was an equal symbol.*/ 		if ((s[++i] = c = getch()) == '='){			setVar = TRUE;c = getch();s[++i] = c;		}else{if (c != EOF){		ungetch(c);}return GETVARIABLE;}}if(c == '-'){		c = getch();	s[++i] = c;			}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);}
/* if s[0] == '-' && s[1] == '\0', return minus operator */	if (i == 1 && s[0] == '-') return '-';	if (setVar){	return SETVARIABLE;	}		return NUMBER;
}char buf=EOF;   /* buffer for ungetch */int getch(void)      /* get a (possibly pushed-back) character */
{return (buf!=EOF) ? buf : getchar();
}void ungetch(int c) /* push character back on input */
{if (buf!=EOF)printf("ungetch: too many characters\n");elsebuf = c;
}

      E x c e r c i s e 4 − 9 Excercise\quad 4-9 Excercise49

      E x c e r c i s e 4 − 10 Excercise\quad 4-10 Excercise410

#include <stdio.h>
#include <stdlib.h> 
#include <ctype.h>
#include <math.h>
#include <string.h> #define MAXOP     100     /* max size of operand or operator */
#define NUMBER    '0'     /* signal that a number was found */
#define SETVARIABLE 's'   /* signal that a variable is being assigned */
#define GETVARIABLE 'g'   /* signal that a variable is being retrieved */
#define NUMVARS 26        /* number of variables supported (a-z) */
#define MAXLINE 1000        /* number of variables supported (a-z) */enum boolean {FALSE, TRUE};int getop(char []);
void push(double);
double pop(void);
void showTop(void);
void duplicate(void);
void swapItems(void);
void clearStack();
void view_stack();	
int getline(char s[], int lim);/* initially as space such that malformed use of '=' won't cause segfaults */
char last_recent = ' '; 
/* array to store the double values for variables. 
Supports variables a through z (lower case). Initial value is 0*/
double varVals[NUMVARS] = {0.0}; /*********************************/
char line[MAXLINE];
int line_i;
/*********************************/
/* reverse Polish calculator */
int main()
{int type;double op2;char s[MAXOP];while (getline(line, MAXLINE) != 0){line_i=0;while ((type = getop(s)) != '\0') {switch (type) {case NUMBER:push(atof(s));break;/****************************************************/				 case SETVARIABLE:if (strlen(s) > 2 && s[1] == '='){int v = s[0];           /* stores variable */int i = 1;              /* start at 1 since while loop needed ++i for a few reasons */while (s[++i] != '\0')  /* this removes the variable name= part of s e.g. if s == "a=123.45" after loop s == "123.45" */s[i - 2] = s[i];    /* shifts chars two to the left by 2 */s[i - 2] = '\0';        /* since '\0' isn't copied, terminate string manually */varVals[v - 'a'] = atof(s); /* convert string to double and store it in array */}elseprintf("error: set variable length too small or incorrectly formatted (%s)\n", s);break;case GETVARIABLE:push(varVals[s[0] - 'a']);  /* convert the variable name to stored value */break;	/****************************************************/				 case '+':push(pop() + pop());break;case '*':push(pop() * pop());break;case '-':op2 = pop();push(pop() - op2);break;case '/':op2 = pop();if (op2 != 0.0)push(pop() / op2);elseprintf("error: zero divisor\n");break;case '%':op2 = pop();if (op2 != 0.0)push(fmod(pop(),op2));elseprintf("error: zero divisor\n");break;/****************************************************/				 case '?':showTop();break;case '#':duplicate();break;case '~':swapItems();break;case '!':clearStack();	break;				/****************************************************/case '$':push(sin(pop()));break;case '@':push(exp(pop()));break;case '^':op2 = pop();push(pow(pop(),op2));break;									// case '\n':// printf("\t%.8g\n", pop());// break;case '\n':view_stack();break;	case '_':printf("The last recently used variable is %c=%8g\n",last_recent, varVals[last_recent-'a']);break;					 default:printf("error: unknown command %s\n", s);break;}}}return 0;
}#define MAXVAL 100   /* maximum depth of val stack */
int sp = 0;          /* next free stack position */
double val[MAXVAL];  /* value stack *//* push: push f onto value stack */
void push(double f)
{if (sp < MAXVAL)val[sp++] = f;elseprintf("error: stack full, can't push %g\n", f);
}/* pop: pop and return top value from stack */
double pop(void)
{if (sp > 0)return val[--sp];else {printf("error: stack empty\n");return 0.0;}
}/* push: push f onto value stack */
void view_stack()
{int i=sp;if (sp >0){while(i>0){printf("view_stack:%8g\n",val[i-1]);i=i-1;}}elseprintf("view_stack:Stack is empty\n");
}/**********************************************************/
void showTop(void)
{if(sp > 0)printf("Top of stack contains: %8g\n", val[sp-1]);elseprintf("The stack is empty!\n");
}void duplicate(void)
{double temp = 0.0;	if((sp > 0) &&(sp < MAXVAL)){temp = pop();push(temp);push(temp);				}elseprintf("The stack is empty!\n");	}void swapItems(void)
{double item1 = 0.0;double item2 = 0.0;	if(sp >= 2){item1 = pop();item2 = pop();push(item1);push(item2);			}elseprintf("The stack is empty!\n");	
}/* pop only returns a value if sp is greater than zero. So setting the
stack pointer to zero will cause pop to return its error */void clearStack(void)
{sp = 0;
}/**********************************************************/#include <ctype.h>
int getch(void);
void ungetch(int);/* getop: get next character or numeric operand */
int getop(char s[])
{int i, c;char setVar = FALSE;i = 0;while ((s[0] = c = line[line_i++]) == ' ' || c == '\t');s[1] = '\0';if (!isdigit(c) && !isalpha(c) && c != '.' && c != '-'){	return c; /* not a number */}if (c >= 'a' && c <= 'z'){last_recent=c;
/* get next char and check if it was an equal symbol.*/ 		if ((s[++i] = c = line[line_i++]) == '='){			setVar = TRUE;c = line[line_i++];s[++i] = c;		}else{if (c != '\0'){		line_i=line_i-1;}return GETVARIABLE;}}if(c == '-'){		c = line[line_i++];	s[++i] = c;			}if (isdigit(c)) /* collect integer part */{	while (isdigit(s[++i] = c = line[line_i++]));}if (c == '.') /* collect fraction part */{	while (isdigit(s[++i] = c = line[line_i++]));}s[i] = '\0';if (c != '\0'){		line_i=line_i-1;}
/* if s[0] == '-' && s[1] == '\0', return minus operator */	if (i == 1 && s[0] == '-') return '-';	if (setVar){	return SETVARIABLE;	}		return NUMBER;
}// /* getop: get next character or numeric operand */
// int getop(char s[])
// {// int i, c;// char setVar = FALSE;// i = 0;// while ((s[0] = c = getch()) == ' ' || c == '\t');// s[1] = '\0';// if (!isdigit(c) && !isalpha(c) && c != '.' && c != '-')// {	// return c; /* not a number */// }// if (c >= 'a' && c <= 'z')// {// last_recent=c;
// /* get next char and check if it was an equal symbol.*/ 		// if ((s[++i] = c = getch()) == '=')// {			// setVar = TRUE;// c = getch();// s[++i] = c;		// }// else// {// if (c != EOF)// {		// ungetch(c);// }// return GETVARIABLE;// }// }// if(c == '-')// {		// c = getch();	// s[++i] = c;			// }// 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);// }
// /* if s[0] == '-' && s[1] == '\0', return minus operator */	// if (i == 1 && s[0] == '-') // return '-';	// if (setVar)// {	// return SETVARIABLE;	// }		// return NUMBER;
// }/* getline:  get line into s, return length */
int getline(char s[], int lim)
{int c, i;i = 0;while (--lim > 0 && (c = getchar()) != EOF && c != '\n')s[i++] = c;if (c == '\n')s[i++] = c;s[i] = '\0';return i;
}

      E x c e r c i s e 4 − 11 Excercise\quad 4-11 Excercise411

#include <stdio.h>
#include <stdlib.h> 
#include <ctype.h>
#include <math.h>
#include <string.h> #define MAXOP     100     /* max size of operand or operator */
#define NUMBER    '0'     /* signal that a number was found */
#define SETVARIABLE 's'   /* signal that a variable is being assigned */
#define GETVARIABLE 'g'   /* signal that a variable is being retrieved */
#define NUMVARS 26        /* number of variables supported (a-z) */enum boolean {FALSE, TRUE};int getop(char []);
void push(double);
double pop(void);
void showTop(void);
void duplicate(void);
void swapItems(void);
void clearStack();
void view_stack();	/* initially as space such that malformed use of '=' won't cause segfaults */
char last_recent = ' '; 
/* array to store the double values for variables. 
Supports variables a through z (lower case). Initial value is 0*/
double varVals[NUMVARS] = {0.0}; /* reverse Polish calculator */
int main()
{int type;double op2;char s[MAXOP];while ((type = getop(s)) != EOF) {switch (type) {case NUMBER:push(atof(s));break;
/****************************************************/				 case SETVARIABLE:if (strlen(s) > 2 && s[1] == '='){int v = s[0];           /* stores variable */int i = 1;              /* start at 1 since while loop needed ++i for a few reasons */while (s[++i] != '\0')  /* this removes the variable name= part of s e.g. if s == "a=123.45" after loop s == "123.45" */s[i - 2] = s[i];    /* shifts chars two to the left by 2 */s[i - 2] = '\0';        /* since '\0' isn't copied, terminate string manually */varVals[v - 'a'] = atof(s); /* convert string to double and store it in array */}elseprintf("error: set variable length too small or incorrectly formatted (%s)\n", s);break;case GETVARIABLE:push(varVals[s[0] - 'a']);  /* convert the variable name to stored value */break;	
/****************************************************/				 case '+':push(pop() + pop());break;case '*':push(pop() * pop());break;case '-':op2 = pop();push(pop() - op2);break;case '/':op2 = pop();if (op2 != 0.0)push(pop() / op2);elseprintf("error: zero divisor\n");break;case '%':op2 = pop();if (op2 != 0.0)push(fmod(pop(),op2));elseprintf("error: zero divisor\n");break;
/****************************************************/				 case '?':showTop();break;case '#':duplicate();break;case '~':swapItems();break;case '!':clearStack();	break;				
/****************************************************/case '$':push(sin(pop()));break;case '@':push(exp(pop()));break;case '^':op2 = pop();push(pow(pop(),op2));break;									// case '\n':// printf("\t%.8g\n", pop());// break;case '\n':view_stack();break;	case '_':printf("The last recently used variable is %c=%8g\n",last_recent, varVals[last_recent-'a']);break;					 default:printf("error: unknown command %s\n", s);break;}}return 0;
}#define MAXVAL 100   /* maximum depth of val stack */
int sp = 0;          /* next free stack position */
double val[MAXVAL];  /* value stack *//* push: push f onto value stack */
void push(double f)
{if (sp < MAXVAL)val[sp++] = f;elseprintf("error: stack full, can't push %g\n", f);
}/* pop: pop and return top value from stack */
double pop(void)
{if (sp > 0)return val[--sp];else {printf("error: stack empty\n");return 0.0;}
}/* push: push f onto value stack */
void view_stack()
{int i=sp;if (sp >0){while(i>0){printf("view_stack:%8g\n",val[i-1]);i=i-1;}}elseprintf("view_stack:Stack is empty\n");
}/**********************************************************/
void showTop(void)
{if(sp > 0)printf("Top of stack contains: %8g\n", val[sp-1]);elseprintf("The stack is empty!\n");
}void duplicate(void)
{double temp = 0.0;	if((sp > 0) &&(sp < MAXVAL)){temp = pop();push(temp);push(temp);				}elseprintf("The stack is empty!\n");	}void swapItems(void)
{double item1 = 0.0;double item2 = 0.0;	if(sp >= 2){item1 = pop();item2 = pop();push(item1);push(item2);			}elseprintf("The stack is empty!\n");	
}/* pop only returns a value if sp is greater than zero. So setting the
stack pointer to zero will cause pop to return its error */void clearStack(void)
{sp = 0;
}/**********************************************************/#include <ctype.h>/* getop: get next character or numeric operand */
int getop(char s[])
{int i;static int c=EOF;	static int unget_flag=0;		char setVar = FALSE;i = 0;if(unget_flag==1){if((c== ' ') || (c == '\t')){while ((s[0] = c = getchar()) == ' ' || c == '\t');	    		    	}	else{s[0] = c;			}unget_flag=0;}else{while ((s[0] = c = getchar()) == ' ' || c == '\t');				}s[1] = '\0';if (!isdigit(c) && !isalpha(c) && c != '.' && c != '-'){	return c; /* not a number */}if (c >= 'a' && c <= 'z'){last_recent=c;
/* get next char and check if it was an equal symbol.*/ 		if ((s[++i] = c = getchar()) == '='){			setVar = TRUE;c = getchar();s[++i] = c;		}else{if (c != EOF){		unget_flag=1;}			return GETVARIABLE;}}if(c == '-'){		c = getchar();	s[++i] = c;			}if (isdigit(c)) /* collect integer part */{	while (isdigit(s[++i] = c = getchar()));}if (c == '.') /* collect fraction part */{	while (isdigit(s[++i] = c = getchar()));}	s[i] = '\0';if (c != EOF){		unget_flag=1;}		
/* if s[0] == '-' && s[1] == '\0', return minus operator */	if (i == 1 && s[0] == '-') return '-';	if (setVar){	return SETVARIABLE;	}		return NUMBER;
}

      E x c e r c i s e 4 − 12 Excercise\quad 4-12 Excercise412

#include <stdlib.h>
#include <stdio.h>
#include <limits.h>
#include <string.h>void itoa_myself(int n, char s[], int minmum);int main(void) 
{char buffer[100];printf("INT_MIN: %d\n", INT_MIN);itoa_myself(INT_MIN, buffer,25);printf("Buffer : %s\n", buffer);printf("\\*******************************\\\n");   printf("378\n");itoa_myself(378, buffer,25);printf("Buffer : %s\n", buffer);printf("\\*******************************\\\n");   printf("-873\n");itoa_myself(-873, buffer,25);printf("Buffer : %s\n", buffer);return 0;
}void itoa_myself(int n, char s[],int minmum) 
{static int i=0;static int recur_num=0;	recur_num=recur_num+1;if(n<0){s[i++] = '-';		}if(n/10){itoa_myself(abs(n/10), s,minmum); } s[i++] = abs(n % 10) + '0';	if(i>minmum){printf("Elements overflow\n");}recur_num=recur_num-1;if(recur_num==0){	s[i] = '\0';	i=0;recur_num=0;	    		}
}

      E x c e r c i s e 4 − 13 Excercise\quad 4-13 Excercise413

#include <stdlib.h>
#include <stdio.h>
#include <limits.h>
#include <string.h>void itoa_myself(int n, char s[], int minmum);
void reverse(char s[]);int main(void) 
{char buffer[100];printf("INT_MIN: %d\n", INT_MIN);itoa_myself(INT_MIN, buffer,25);printf("Buffer : %s\n", buffer);return 0;
}void itoa_myself(int n, char s[], int minmum) 
{int i, sign;sign = n;i = 0;do {s[i++] = abs(n % 10) + '0';} while ( n /= 10 );if (sign < 0)s[i++] = '-';while(i<minmum){s[i++] = ' ';		}	s[i] = '\0';reverse(s);
}void reverse(char s[]) 
{int c;	static int first_flag=1;		static int i=0;	static int j=0;if(first_flag==1){first_flag=0;j=strlen(s)-1;}if ( i < j ) {c = s[i];s[i] = s[j];s[j] = c;i=i+1;j=j-1;reverse(s);}
}

      E x c e r c i s e 4 − 14 Excercise\quad 4-14 Excercise414

#include <stdio.h>#define swap(t,x,y) {              \t temp=x;  \x=y;       \y=temp;    \}int main(void) 
{int a=6;int b=9;swap(int,a,b)printf("a=%d,b=%d\n", a,b);return 0;
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/diannao/4022.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

【iOS】类与对象底层探索

文章目录 前言一、编译源码二、探索对象本质三、objc_setProperty 源码探索四、类 & 类结构分析isa指针是什么类的分析元类元类的说明 五、著名的isa走位 & 继承关系图六、objc_class & objc_objectobjc_class结构superClassbitsclass_rw_tclass_ro_tro与rw的区别c…

探索光纤通信核心:光分路器光衰深度解析

光分路器是光纤通信系统中的一种关键组件&#xff0c;它能够将输入的光信号分配到多个输出端口。在光分路器中&#xff0c;光衰是指光信号在传输过程中从输入端口到输出端口的损耗。光衰的大小直接影响到光纤通信系统的性能和稳定性。因此&#xff0c;正确计算和测量光分路器的…

03-JAVA设计模式

设计模式GOF23 GOF23是指由设计模式经典名著《Design Patterns: Elements of Reusable Object-Oriented Software》&#xff08;中译本名为《设计模式——可复用面向对象软件的基础》&#xff09;的四位作者Erich Gamma、Richard Helm、Ralph Johnson、以及John Vlissides提出…

leetcode 2639.查询网格图种每一列的宽度

其实这道题简单的模拟就行。 一开始作者想着用列优先的遍历进行求每一列的最大值&#xff0c;但是发现leetcode中这个所给数组是不确定的&#xff0c;所以就改用了原来的遍历方法. 这里定义了一个ans数组就是为了记录每一列里面的最大值的&#xff0c;我们首先需要把数组里面…

windows驱动开发-I/O请求(一)

I/O请求是内核中非常重要的部分&#xff0c;所有的驱动功能都使用I/O请求来交互&#xff0c;故理解了I/O请求也就理解了驱动的工作原理。 DeviceIoControl 这个函数主要就是用于发送I/O请求: BOOL DeviceIoControl (HANDLE hDevice, // CreateFile返回的设备句柄…

在Elasticsearch 7.9.2中安装IK分词器并进行自定义词典配置

Elasticsearch是一个强大的开源搜索引擎&#xff0c;而IK分词器是针对中文文本分析的重要插件。本文将引导您完成在Elasticsearch 7.9.2版本中安装IK分词器、配置自定义词典以及验证分词效果的全过程。 步骤一&#xff1a;下载IK分词器 访问IK分词器的GitHub发布页面&#xf…

游戏发行困境及OgGame云游戏解决方案简述

随着全球化浪潮的持续推进&#xff0c;中国游戏开发者们不再满足于国内市场的发展&#xff0c;而是开始将目光投向更为广阔的海外市场。这一趋势的崛起背后&#xff0c;是中国企业意识到国际化是其发展的必由之路&#xff0c;也是游戏行业突破国内困境的体现。本文将简要阐述游…

发那科FANUC机器人R-2000iB平衡缸维修攻略

在发那科机器人中&#xff0c;平衡缸扮演着稳定机械臂运动的关键角色。它通过内部的压力调节来平衡负载&#xff0c;保证机器人的精准定位和平稳操作。一旦出现法兰克机械手平衡缸故障或损坏&#xff0c;机器人的性能可能会大打折扣&#xff0c;因此及时且正确的FANUC机械手平衡…

并并并并·病查坤

P1、什么是并查集 引用自百度百科&#xff1a; 并查集&#xff0c;在一些有N个元素的集合应用问题中&#xff0c;我们通常是在开始时让每个元素构成一个单元素的集合&#xff0c;然后按一定顺序将属于同一组的元素所在的集合合并&#xff0c;其间要反复查找一个元素在哪个集合…

银行押款车远程监控系统的实际需求与特点

随着金融行业的快速发展&#xff0c;银行押款车的安全性问题日益受到重视。传统的押款车监控方式已经无法满足现代安全管理的需求&#xff0c;因此&#xff0c;一种结合先进技术的远程监控系统应运而生。本文旨在探讨在运钞车上安装车载摄像机和集成有GPS、无线4G网络传输模块的…

C语言 switch语句

之前 我们讲了 if 和 嵌套的if分支语句 但其实 多分支语句 我们还可以用 switch 有时 switch 语句可以简化逻辑代码 switch语句也称之为开关语句&#xff0c;其像多路开关一样&#xff0c;使程序控制流程形成多个分支&#xff0c;根据一个表达式的不同取值&#xff0c;选择其…

社交巨头与去中心化:解析Facebook在区块链的角色

在数字化时代&#xff0c;社交媒体已经成为人们日常生活中不可或缺的一部分。作为全球最大的社交媒体平台&#xff0c;Facebook 在社交领域的影响力无可置疑。然而&#xff0c;随着区块链技术的崛起&#xff0c;Facebook 也开始探索如何将这一技术应用于其平台&#xff0c;以适…

UE4_动画基础_FootIK

角色由于胶囊体的阻挡&#xff0c;双脚与地面平行&#xff0c;不会与斜坡、台阶等贴合&#xff0c;有一条腿会处于悬空状态&#xff0c;通过双骨骼IK节点使一只脚太高&#xff0c;让后胶囊体下降&#xff0c;修正双脚的角度。这就是逆向运动IK的方法。 一、新建第三人称模板游戏…

PG一键安装

1.RPM包一键安装 #!/bin/bash ## # 脚本名 : PG_RPM_ShellInstall.sh # 创建时间 : 2024-03-08 22:00:00 # 更新时间 : 2024-03-09 23:00:00 # 描述 : PostgreSQL 数据库RPM离线一键安装脚本&#xff08;单机&#xff09; # Linux系统 : Liunx7 # PG…

微信小程序开发:2.小程序组件

常用的视图容器类组件 View 普通的视图区域类似于div常用来进行布局效果 scroll-view 可以滚动的视图&#xff0c;常用来进行滚动列表区域 swiper and swiper-item 轮播图的容器组件和轮播图的item项目组件 View组件的基本使用 案例1 <view class"container"&…

新版IDEA频繁卡顿(UI 冻结)解决方案

当开启多项目多环境或复杂项目大项目时&#xff0c;新版IDEA会频繁卡顿冻结UI。 因为IDEA是Java写的&#xff0c;卡顿自然就是因为频繁Full GC导致的。 新版IDEA使用了G1垃圾回收器&#xff0c;当期望STW内一直无法有效回收大对象时&#xff0c;就会触发Full GC&#xff08;G1的…

【ARM 裸机】NXP 官方 SDK 使用

在前几节中&#xff0c;学习了如何编写汇编的 led 驱动、C 语言的 led 驱动、模仿 STM32 进行开发&#xff0c;我们都是自己写外设寄存器的结构体&#xff0c;外设非常的多&#xff0c;写起来费时费力&#xff0c;NXP 针对 I.MX6ULL 编写了一个 SDK 包&#xff0c;这个 SDK 包就…

解析Python中获取当前线程名字的方法及多线程编程实践

&#x1f47d;发现宝藏 前些天发现了一个巨牛的人工智能学习网站&#xff0c;通俗易懂&#xff0c;风趣幽默&#xff0c;忍不住分享一下给大家。【点击进入巨牛的人工智能学习网站】。 Python 获取当前线程的名字 在多线程编程中&#xff0c;了解当前线程的名字是一项重要的任…

SQL异常

异常 EXCEPTION 预定义异常 系统已经设置好的异常&#xff0c;包含了异常名&#xff0c;异常代码&#xff0c;异常信息组成 CASE NOT FOUND 未知异常&#xff1a;OTHERS 异常信息&#xff1a;SQLERRM 错误代码&#xff1a;SQLCODE 有各种各样的很多异常 捕获异常的语法 DE…

Python中的多点坐标

Python中的多点坐标 在Python中&#xff0c;多点坐标通常表示为一组元组或列表的列表&#xff0c;其中每个内部列表或元组表示一个点的坐标。这些坐标可以是二维的&#xff08;x, y&#xff09;&#xff0c;三维的&#xff08;x, y, z&#xff09;&#xff0c;或者更高维度的&a…