📄 parse.c
字号:
/* parse.c */#include <stdio.h>#include <string.h>#include <malloc.h>#include "parse.h"/* Build a string of up to the specified size from the standard input. */char *build(int size, char delim, int *len){ register int i; char *gen,hex2c[2];/* Allocate space for the data according to requested size. */ if(!(gen=malloc(sizeof(char)*(size+1)))) return gen;/* As long as there is still input, keep going. */ for(i=0; (*len); i++){ if(i>size+1){/* Data item is larger than requested size. */ free(gen); return (char *)NULL; } gen[i]=(char)getchar(); --(*len); if((gen[i] == delim) || (gen[i]==EOF)){/* Found the end of the current input field. Terminate and return the parsed field. */ gen[i]='\0'; return gen; }/* Convert plus sign to space. */ if(gen[i]=='+') gen[i]=' ';/* Convert an escaped special character back to an ASCII character. */ if(gen[i]=='%'){ hex2c[0]=getchar(); --(*len); hex2c[1]=getchar(); --(*len); gen[i] = (!(isalpha(hex2c[0])) ? (hex2c[0] - '0') : ((hex2c[0] & 0xdf) - 'A' + 10)) << 4; gen[i] += (!(isalpha(hex2c[1])) ? (hex2c[1] - '0') : ((hex2c[1] & 0xdf) - 'A' + 10)); } }/* Reached the end of the input block. Terminate and return the string. */ gen[i]='\0'; return gen;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -