int main( void ) { char *text, *word, *ptr, *wordEnd; size_t len; char chr, tmpchr; puts( "This program search character in a text and print all words, that contain given character." ); puts( "Enter character(a-z, A-Z, 0-9):" ); while( 1 ) { chr = (char)getchar(); if( IsGraph( tmpchr = (char)getchar() ) ) { ungetc( tmpchr, stdin ); } if( IsAlnum( chr ) == false ) { puts( "Wrong character, try again:" ); } else { break; } } text = Input(); if( text == NULL ) { puts( "Not enough memory." ); return 1; } ptr = text; while( wordEnd = FindWord( ptr, chr ) ) { len = 1; word = wordEnd; while( IsAlnum( word[-1] ) && word >= text ) { word--; len++; } word = memcpy( malloc( len + 1 ), word, len ); if( word == NULL ) { puts( "Memory is not enough" ); break; } else { word[len] = 0; printf( "\"%s\" is the word, that contain '%c'\n", word, chr ); free( word ); } ptr = wordEnd + 1; } free( text ); return 0; }
/* * Object validity checker. Returns the data pointer. */ static rleaf_GRAPH * check_graph( VALUE self ) { // rleaf_log_with_context( self, "debug", "checking a Redleaf::Graph object (%d).", self ); Check_Type( self, T_DATA ); if ( !IsGraph(self) ) { rb_raise( rb_eTypeError, "wrong argument type %s (expected Redleaf::Graph)", rb_obj_classname( self ) ); } return DATA_PTR( self ); }
Private bool valid_name(char * p) { bool status = FALSE; if ((strcmp(p, ".") == 0) || (strcmp(p, "..") == 0)) return TRUE; if (strlen(p) > 0) { while(((*p == ' ') || IsGraph(*p)) && (strchr(df_restricted_chars, *p) == NULL)) { p++; } status = (*p == '\0'); } return status; }
static int exec(FILE* fp, ENC_INFO* einfo) { #define NCOL 8 int c, val, enc; enc = einfo->num; fprintf(fp, "static const unsigned short Enc%s_CtypeTable[256] = {\n", einfo->name); for (c = 0; c < 256; c++) { val = 0; if (IsNewline(enc, c)) val |= BIT_CTYPE_NEWLINE; if (IsAlpha (enc, c)) val |= (BIT_CTYPE_ALPHA | BIT_CTYPE_ALNUM); if (IsBlank (enc, c)) val |= BIT_CTYPE_BLANK; if (IsCntrl (enc, c)) val |= BIT_CTYPE_CNTRL; if (IsDigit (enc, c)) val |= (BIT_CTYPE_DIGIT | BIT_CTYPE_ALNUM); if (IsGraph (enc, c)) val |= BIT_CTYPE_GRAPH; if (IsLower (enc, c)) val |= BIT_CTYPE_LOWER; if (IsPrint (enc, c)) val |= BIT_CTYPE_PRINT; if (IsPunct (enc, c)) val |= BIT_CTYPE_PUNCT; if (IsSpace (enc, c)) val |= BIT_CTYPE_SPACE; if (IsUpper (enc, c)) val |= BIT_CTYPE_UPPER; if (IsXDigit(enc, c)) val |= BIT_CTYPE_XDIGIT; if (IsWord (enc, c)) val |= BIT_CTYPE_WORD; if (IsAscii (enc, c)) val |= BIT_CTYPE_ASCII; if (c % NCOL == 0) fputs(" ", fp); fprintf(fp, "0x%04x", val); if (c != 255) fputs(",", fp); if (c != 0 && c % NCOL == (NCOL-1)) fputs("\n", fp); else fputs(" ", fp); } fprintf(fp, "};\n"); return 0; }