这篇教程C++ ungetch函数代码示例写得很实用,希望能帮到您。
本文整理汇总了C++中ungetch函数的典型用法代码示例。如果您正苦于以下问题:C++ ungetch函数的具体用法?C++ ungetch怎么用?C++ ungetch使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。 在下文中一共展示了ungetch函数的30个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。 示例1: gettoken/** get next token/lexem */int gettoken(void) { int c, getch(void); void ungetch(int); char *p = token; /** skip whitespaces */ while ((c = getch()) == ' ' || c == '/t') ; /** collect '(' and "()" tokens */ if (c == '(') { if ((c = getch()) == ')') { strcpy(token, "()"); return tokentype = PARENS; } else { ungetch(c); return tokentype = '('; } } /** collect "[SIZE]" tokens */ else if (c == '[') { for (*p++ = c; (*p++ = getch()) != ']'; ) ; *p = '/0'; return tokentype = BRACKETS; } /** collect "NAME" tokens */ else if (isalpha(c)) { for (*p++ = c; isalnum(c = getch()); ) *p++ = c; *p = '/0'; ungetch(c); return tokentype = NAME; } /** collect everything else */ else return tokentype = c;}
开发者ID:kanner,项目名称:KnR_solutions,代码行数:40,
示例2: get_tokenint get_token(void){ int c, getch(void); void ungetch(int); char *p = token; while ((c = getch()) == ' ' || c == '/t') ; if (c == '(') { if ((c = getch()) == ')') { strcpy(token, "()"); return tokentype = PARENS; } else { ungetch(c); return tokentype = '('; } } else if (c == '[') { for (*p++ = c; (*p++ = getch()) != ']'; ) ; *p = '/0'; return tokentype = BRACKETS; } else if (isalpha(c)) { for (*p++ = c; isalnum(c = getch()); ) *p++ = c; *p = '/0'; ungetch(c); return tokentype = NAME; } else return tokentype = c;}
开发者ID:dpflann,项目名称:review,代码行数:39,
示例3: mainint main(int argc, char *argv[]) { char word[MAXWORD]; char word2[MAXWORD]; int i; struct nlist *np; struct tnode *root; root = NULL; while (getword(word, MAXWORD) != EOF) { if (strcmp(word, "#define") == 0 && getword(word, MAXWORD) != EOF && isalpha(word[0]) && getword(word2, MAXWORD) != EOF) { install(word, word2); } else if (isalpha(word[0])) { if ((np = lookup(word)) != NULL) { i = strlen(np->defn) - 1; while (i >= 0) { ungetch(np->defn[i]); i--; } } else { root = addtree(root, word); } } } /* INPUT: #define a x #define x e a x x c v b a q e OUTPUT: 1 b 1 c 5 e 1 q 1 v */ treeprint(root); return 0;}
开发者ID:devilTian,项目名称:Fragment,代码行数:51,
示例4: definedbool QFile::open( int m, FILE *f ){ if ( isOpen() ) {#if defined(QT_CHECK_RANGE) qWarning( "QFile::open: File already open" );#endif return FALSE; } init(); setMode( m &~IO_Raw ); setState( IO_Open ); fh = f; ext_f = TRUE; struct stat st; ::fstat( fileno(fh), &st );#if defined(QT_LARGEFILE_SUPPORT)#if !defined(QT_ABI_QT4) off_t tmp = ftello( fh ); ioIndex = tmp > UINT_MAX ? UINT_MAX : (Offset)tmp;#else ioIndex = (Offset)ftello( fh );#endif#else ioIndex = (Offset)ftell( fh );#endif if ( (st.st_mode & S_IFMT) != S_IFREG || f == stdin ) { //stdin is non seekable // non-seekable setType( IO_Sequential ); length = INT_MAX; ioIndex = 0; } else {#if defined(QT_LARGEFILE_SUPPORT) && !defined(QT_ABI_QT4) length = st.st_size > UINT_MAX ? UINT_MAX : (Offset)st.st_size;#else length = (Offset)st.st_size;#endif if ( !(flags()&IO_Truncate) && length == 0 && isReadable() ) { // try if you can read from it (if you can, it's a sequential // device; e.g. a file in the /proc filesystem) int c = getch(); if ( c != -1 ) { ungetch(c); setType( IO_Sequential ); length = INT_MAX; ioIndex = 0; } resetStatus(); } } return TRUE;}
开发者ID:aroraujjwal,项目名称:qt3,代码行数:51,
示例5: getintint getint(int *pn){ /* Get next integer from input into *pn. */ int c; int sign; while (isspace(c = getch())) continue; if (!isdigit(c) && c != EOF && c != '+' && c != '-') { printf("%c is not a number or sign/n", c); ungetch(c); return 0; } sign = (c == '-') ? -1 : 1; if (c == '+' || c == '-') { c = getch(); if (!isdigit(c)) { /* push both characters back on input */ ungetch((sign == 1) ? '+' : '-'); ungetch(c); return 0; } } for (*pn = 0; isdigit(c); c = getch()) *pn = 10 * *pn + (c - '0'); *pn *= sign; if (c != EOF) ungetch(c); return c;}
开发者ID:weezybusy,项目名称:KnR2,代码行数:38,
示例6: getop/*gettop: get next character or operand */int getop(char s[]){ int i, c; double r; while ( (s[0] = c = getch() ) == ' ' || c == '/t') ; s[1] = '/0'; i = 0; if (!isdigit(c) && c != '.' && c != '-') return c; /* not a number */ if (c == '-') /* section to check negative values */ if (isdigit(c = getch()) || c == '.') /* if a negative symbol detects */ s[++i] = c; /* negative number*/ /* check whether next character is a number or a '.' if so */ else { /* that is negative number & that will be stored in the array to be returned*/ if (c != EOF) /* else return a negative operator to compute */ ungetch(c); return '-'; } if (isdigit(c)) /* collect integer parts */ while (isdigit(s[++i] = c = getchar())) ; if (c == '.') while (isdigit(s[++i] = c = getchar())); ; s[i] = '/0'; if (c != EOF) ungetch(c); return NUMBER;/* if (c == '/n') { i = 1; r = val[--sp]; printf("/t%.8g", r); } */}
开发者ID:ArunRamachandran,项目名称:K-R-Excercise-Solutions,代码行数:39,
示例7: getop/* getop: get next operator or numeric operand */int getop(char input[]) { int i, c; while ((input[0] = c = getch()) == ' ' || c == '/t') { ; } input[1] = '/0'; if (!isdigit(c) && c != '.' && c != '-') { return c; /* not a number */ } i = 0; if (c == '-') { if (isdigit(input[++i] = c = getch())) { ; /* negative number */ } else { ungetch(c); /* not a negative, so backup and return negative */ return '-'; } } if (isdigit(c)) { /* collect integer part */ while (isdigit(input[++i] = c = getch())) { ; } } if (c == '.') { /* collect fraction part */ while (isdigit(input[++i] = c = getch())) { ; } } input[i] = '/0'; if (c != EOF) { ungetch(c); } return NUMBER;}
开发者ID:threePhase,项目名称:K-R-Exercises,代码行数:39,
示例8: getop/* getop: получает следующий оператор или операнд */int getop(char s[]){ int i = 0, c; while ((c = getch()) == ' ' || c == '/t' ) ; s[1] = '/0'; if (!isdigit(c) && c != '.') { if (c == '-') { s[i++] = c; if (!isdigit(c = getch())) { ungetch(c); return s[--i]; /* не число */ } } else { return c; /* не число */ } } /* накапливаем целую часть */ if (isdigit(c)) { s[i++] = c; while (isdigit(s[i++] = c = getch())) ; } /* накапливаем дробную часть */ if (c == '.') { s[i++] = c; while (isdigit(s[i++] = c = getch())) ; } if (!isdigit(s[i - 1])) --i; if (c != EOF) ungetch(c); s[i] = '/0'; return NUMBER;}
开发者ID:sinitcin,项目名称:CLearn,代码行数:39,
示例9: ungets// Возвращает строку s во входной потокvoid ungets(char s[]) { // Узнаём размер int pos; for (pos = 0; s[pos] != '/0' && s[pos] != '/n' && s[pos] != EOF; pos++) ; --pos; // Возвращаем с конца в буфер while (pos >= 0) { ungetch(s[pos]); --pos; }}
开发者ID:sinitcin,项目名称:CLearn,代码行数:15,
示例10: ungets/* ungets: push back an entire string onto the input */void ungets(char s[]){ char c; int i; /* read input line and push back all its characters */ for (i = 0; (c = getchar()) != NEWLINE; i++) ungetch(c); s[i++] = NEWLINE; s[i] = NULLCHAR; /* get pushed back characters, newline and nullchar remain in place */ for (i = i - 2; i >= 0; i--) s[i] = getch();}
开发者ID:marianomacchi,项目名称:KNR,代码行数:15,
示例11: kbhitint kbhit(void) { int temp; if (!screen_initialized) init_screen(); wtimeout(stdscr, 0); if ((temp = wgetch(stdscr)) != EOF) { ungetch(temp); nodelay(stdscr, FALSE); return TRUE; } else { nodelay(stdscr, FALSE); return FALSE; }}
开发者ID:bcho-archive,项目名称:aqulia,代码行数:14,
示例12: cgetschar *cgets(char *string){ unsigned len = 0; unsigned int maxlen_wanted; char *sp; int c; /* * Be smart and check for NULL pointer. * Don't know wether TURBOC does this. */ if (!string) return (NULL); maxlen_wanted = (unsigned int) ((unsigned char) string[0]); sp = &(string[2]); /* * Should the string be shorter maxlen_wanted including or excluding * the trailing '/0' ? We don't take any risk. */ while (len < maxlen_wanted - 1) { c = getch(); /* * shold we check for backspace here? * TURBOC does (just checked) but doesn't in cscanf (thats harder * or even impossible). We do the same. */ if (c == '/b') { if (len > 0) { cputs("/b /b"); /* go back, clear char on screen with space and go back again */ len--; sp[len] = '/0'; /* clear the character in the string */ } } else if (c == '/r') { sp[len] = '/0'; break; } else if (c == 0) { /* special character ends input */ sp[len] = '/0'; ungetch(c); /* keep the char for later processing */ break; } else { sp[len] = putch(c); len++; } } sp[maxlen_wanted - 1] = '/0'; string[1] = (char) ((unsigned char) len); return (sp);}
开发者ID:ThomasDickey,项目名称:vile-snapshots,代码行数:50,
示例13: getwordint getword(char *word, int lim){ int c, getch(void); void ungetch(int); char *w = word; while (isspace(c = getch())){ /*if (c=='/n'){ return 0*/; // } ;} if(c==EOF) return EOF; if (isalpha(c)){ *w++ = c; } if (!isalpha(c)) { if(c=='/'){ if((c=getch())=='*'){ while((c=getch())!='*') ; if((c=getch())=='/'){ if((c=getch())=='/n'){ return 1;} } } } if(c=='"'){ while((c=getch())!='"') ; if((c=getch())=='/n') return 1; } } for ( ; --lim > 0; w++) if (!isalnum(*w = getch())&&*w!='_'&&*w!='.') { if(*w=='/n'){ *w='/0'; return 1; } ungetch(*w); break; } *w = '/0'; return 1;}
开发者ID:aaabhilash97,项目名称:kr,代码行数:50,
示例14: commentint comment(void){ int getch(void); void ungetch(int); int c; while((c = getch()) != EOF) if(c == '*'){ if((c = getch()) == '/') break; else ungetch(c); } return c;}
开发者ID:charlesyoungwin,项目名称:cPractice,代码行数:14,
示例15: mainint main(void) { int c; while ((c = getch()) != EOF) { if (c == '/n'); // Do nothing else if (c >= '0' && c <= '9') { ungetch(c); printf("[%c] is a number/n", getch()); } else printf("[%c] is not a number/n", c); } return 0;}
开发者ID:DeadDork,项目名称:learning_c,代码行数:14,
示例16: getdoubledouble getdouble(double *pn) { int i = 0, e = 0; double b, c, sign; while ((c = getch()) == ' ' || c == '/t') ; if (!isdigit(c) && c != EOF && c != '+' && c != '-' && c != '/n' && c != '.') c = getdouble(&array[++n]); sign = (c == '-') ? -1 : 1; if (c == '+' || c == '-') { if (isdigit(b = getch())) c = b; else c = getdouble(&array[++n]); } if (c == '/n') { printf("/n"); c = getdouble(&array[++n]); } if (c != EOF) { *pn = 0; i = 10 * i + (c - '0'); while (isdigit(c = getch())) i = 10 * i + (c - '0'); if (c == '.') { while(isdigit(c = getch())) { *pn = 10.0 * *pn + (c - '0'); e--; } } while (e < 0) { *pn *= 0.1; e++; } *pn += i; *pn *= sign; ungetch(c); } return c;}
开发者ID:Dobroserdoff,项目名称:C,代码行数:50,
示例17: whileintPOL::gettok (TOKEN *tok){ int c, toktype; int inum; double fnum; int toksiz = MAXTOK; /* maximum length of token string */ while ((c = inchar()) == BLANK || c == TAB) ; ungetch (c); c = lookchar(); toktype = type(c); fnum = 0.0; inum = 0; if (c == BLANK || c == TAB) { /* skip white space */ getblank(tok->tokstr, toksiz); toktype = TT_BLANK; } else if (toktype == LETTER) { toktype = getalpha (tok->tokstr, toksiz); } else if (c == meta.str) { /* quoted string */ getquote (tok->tokstr, toksiz); toktype = TT_STRING; } else if (type(c) == DIGIT || c == PLUS || c == HYPHEN || c == PERIOD) { toktype = getnumber (tok->tokstr, toksiz, &fnum, &inum); } else if (c == EOF) { tok->tokstr[0] = EOS; toktype = TT_EOF; } else { c = inchar(); tok->tokstr[0] = c; tok->tokstr[1] = EOS; toktype = TT_SPECLCHAR; } tok->type = toktype; tok->ready = true; if (tok->type == TT_REAL || tok->type == TT_INT) { tok->fnum = fnum; tok->inum = inum; } else { tok->fnum = 0.0; tok->inum = 0; } return (toktype);}
开发者ID:leila1349,项目名称:OPT_recon,代码行数:50,
示例18: getfloatint getfloat(float *pn){ int c, sign; float power; while(isspace(c=getch() )) ; if( !isdigit(c) && c !=EOF && c !='+' && c!= '-' && c != '.') { ungetch(c); return 0; } sign = (c== '-')? -1:1; if (c== '+' || c == '-') if(!isdigit(c =getch() && c != '.'){ ungetch(c); return 0; } for(*pn =0; isdigit(c); c=getch()) *pn = 10.0* *pn + (c - '0'); if(c == '.') getch(c); for(*pn=0, power =1.0; isdigit(c); c=getch()){ *pn = 10.0 * *pn + (c - '0'); power *= 10.0; } *pn *= (sign/power); if( c != EOF) ungetch(c); return c; }
开发者ID:ejjy,项目名称:Kernighan---Ritchie-Problem-Solutions,代码行数:37,
示例19: gettokenint gettoken(void) /* return next token */{ int c,getch(void); void ungetch(int); char *p = token; if(prevtoken==YES) { prevtoken = NO; return tokentype; } while((c=getch())==' '||c=='/t'){ ; } if(c=='('){ if((c=getch())==')'){ strcpy(token,"()"); return tokentype=PARENS; }else{ ungetch(c); return tokentype=')'; } }else if(c=='['){ for(*p++=c;(*p++=getch())!=']';) ; *p='/0'; return tokentype = BRACKETS; }else if(isalpha(c)){ for(*p++=c;isalnum(c=getch());){ *p++=c; } *p='/0'; ungetch(c); return tokentype = NAME; }else{ return tokentype=c; }}
开发者ID:idoku,项目名称:The-C-Programming-Language-KnR,代码行数:37,
示例20: getop/* getop: get next operator or numeric operand */int getop(char s[]){ int i, c; while ((s[0] = c = getch()) == ' ' || c == '/t') { ; } s[1] = '/0'; if (!isdigit(c) && c != '.') { if (c == COMMAND) { /* a command, read the command till a non-printable character */ for (i = 0; (s[i] = c = getch()) != ' ' && c != '/n' && c != '/t' && c != EOF; ++i) { ; } ungetch(c); /* return the extra character read */ s[i] = '/0'; /* terminate the command string */ return COMMAND; } return c; /* not a number, not a comamnd, this is an operator */ } 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;}
开发者ID:haimoz,项目名称:HelloC,代码行数:38,
示例21: getop/* getop: get next operator or numeric operand*/int getop(char s[]){ int i, c; int c2; while ((c = getch()) == ' ' || c == '/t') ; s[0] = c; s[1] = '/0'; i = 1; if (!isdigit(c) && c != '.') { if (c == '-'){ c2 = getch(); if (isdigit(c2) || c2 == '.') { s[i++] = c2; } else { ungetch(c2); return c; } } else return c; } while (isdigit(c = getch())) s[i++] = c; if (c == '.') { s[i++] = c; while (isdigit(c = getch())) s[i++] = c; } s[i] = '/0';// if (c != EOF) ungetch(c); return NUMBER;}
开发者ID:lijiansysu,项目名称:c_practice,代码行数:38,
示例22: getwordint getword(char *word, int lim, int *lineNum){ int c; char *w = word; while (isspace(c = getch())){ //出现换行符 if ('/n' == c){ (*lineNum)++; } } if (c != EOF && '/' != c){ *w++ = c; } if (!isalpha(c) && '_' != c && '/' != c){ *w = '/0'; return c; } if ((isalpha(c) || '_' == c) && '/' != c){ for (; --lim > 0; w++){ if (!isalnum(*w = getch()) && '_' != *w){ ungetch(*w); break; } } } else if ('/' == c){ if ('*' == (c = getch())){ comment(); } else{ ungetch(c); } } *w = '/0'; return word[0];}
开发者ID:leichaojian,项目名称:K-R,代码行数:37,
示例23: getnextokenchar *getnextoken(void){ int c; char *bp = tokbuf; for (;;) { if ((c = getch()) < 0) return 0; if (c == ' ' || c == '/t') continue; if (c == '/n') { *bp++ = c; *bp = 0; return tokbuf; } /* start of something */ ungetch(c); break; } for (;;) { if ((c = getch()) < 0) { ungetch(c); if (bp > tokbuf) { *bp = 0; return tokbuf; } return 0; } else if (c == ' ' || c == '/t' || c == '/n') { ungetch(c); *bp = 0; return tokbuf; } *bp++ = c; } return 0; /* not reached */}
开发者ID:9nut,项目名称:plan9,代码行数:36,
示例24: getintint getint ( int *pn ) { int c = 0; int sign = 0; while ( isspace ( c = getch () ) ) { } if ( ! isdigit ( c ) && c != EOF && c != '+' && c != '-' ) {// ungetch ( c ); return 0; }; sign = ( c == '-' ) ? ( -1 ) : 1; if ( c == '+' || c == '-' ) { c = getch (); if ( ! isdigit ( c ) ) { ungetch ( ( sign == 1 ) ? '+' : '-' ); return 0; } }; for ( *pn = 0; isdigit ( c ); c = getch () ) { *pn = 10 * *pn + ( c - '0' ) ; }; *pn *= sign; if ( c != EOF ) { ungetch ( c ); } return c;}
开发者ID:andrew0snake,项目名称:5,代码行数:36,
示例25: getop/* getop: get next operator or numeric operand, return type */int getop(char s[]){ int i, c, type; i = 0; while ( (s[i] = c = getch()) == ' ' || c == '/t') ; /* skip white space */ if (c == '-') { /* '-' could be operator or negative indicator */ s[++i] = c = getch(); if (!isdigit(c)) { ungetch(c); s[i] = '/0'; return s[0]; } } if (isop(c) || c == '/n') { s[i] = '/0'; return c; } else if (isdigit(c) || c == '.') { /* digit */ type = NUMBER; if (isdigit(c)) /* collect integer part */ while (isdigit(s[++i] = c = getch())) ; if (c == '.') /* collect fraction part */ while (isdigit(s[++i] = c = getch())) ; } else { /* handles any other input */ while ( (s[++i] = c = getch()) != ' ' && c != '/t' && c != '/n') ; type = optype(s, i-1); } s[i] = '/0'; if (c != EOF) ungetch(c); return type;}
开发者ID:tcharding,项目名称:self_learning,代码行数:37,
示例26: getintint getint(int *pn) { int c, sign = 1; c = getch(); while(isspace(c)) { c = getch(); } if(c != '+' && c != '-' && !isdigit(c) && c != EOF) { ungetch(c); return 0; } if(c == '+' || c == '-') { if(c == '-') { sign = -1; } c = getch(); if(!isdigit(c)) { ungetch(c); ungetch(sign == 1 ? '+' : '-'); return 0; } } *pn = 0; while(isdigit(c)) { *pn = *pn * 10 + c - '0'; c = getch(); } *pn *= sign; if(c != EOF) { ungetch(c); } return c;}
开发者ID:qrsrjm,项目名称:LearningC,代码行数:36,
示例27: mainint main(int argc, char *argv[]){ // awesome code goes here: int c; while ((c = getch()) != EOF) { // if (c >= '0' && c <= '9') printf("%c", c); if (c < '0' && c > '9') ungetch(c); //printf( } return 0;}
开发者ID:Geovo,项目名称:iCu,代码行数:15,
示例28: getfloat/* getfloat - get next floating point value from input into *f * * handle strings of digits with decimal points for now: * * 12.3 -89.0 23435.34301 * */int getfloat(double *f){ double val, power; int c, sign; while (isspace(c = getch())) /* skip white space */ ; if (!isdigit(c) && c != EOF && c != '+' && c != '-' && c != '.') { ungetch(c); return 0; } sign = (c == '-') ? -1 : 1; if (c == '+' || c == '-') { c = getch(); if (!isdigit(c) && c != '.') { ungetch(c); return 0; } } for (val = 0.0; isdigit(c); c = getch()) val = 10.0 * val + (c - '0'); if (c == '.') c = getch(); for (power = 1.0; isdigit(c); c = getch()) { val = 10.0 * val + (c - '0'); power *= 10.0; } *f = sign * val / power; if (c != EOF) ungetch(c); return(c);}
开发者ID:wurzelstumpf,项目名称:cproglang,代码行数:43,
示例29: isAssignerint isAssigner(char s []){ int nextChar; if (s[0] == '-') { nextChar = getch(); if (nextChar != '>') { ungetch(nextChar); return 0; } return 1; } return 0;}
开发者ID:simsimzone,项目名称:ch4,代码行数:15,
示例30: getword// getword: get word inputint getword(char *w, int lim) { int c; char *word = w; while (isspace(c=getch())); if (!isalpha(c) && c != '_') return c; for (*w++=c; w-word<lim-1 && (isalnum(c=getch()) || c=='_'); *w++=c); if (w-word < lim-1) { ungetch(c); c = word[0]; } *w = '/0'; return c;}
开发者ID:Prince781,项目名称:k-and-r,代码行数:16,
注:本文中的ungetch函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 C++ unguard函数代码示例 C++ ungetc函数代码示例 |