int32 Interp::runScript(char* script, uint32 size, void* context) { char* buf = script, * line = NULL; char* token = NULL, * param_string = NULL; int32 out = 0, current_line = 0, ret = 0, k = 0; while (1) { line = Utils::getToken(&buf, CRLF, size, 2); if (!line) break; /* remove '\n' and blanks */ out = (int32) strlen(line); while (--out && isspace(toascii(line[out]))) line[out] = 0; /* remove blanks */ k = (int32) strlen(line); while (k && isspace(toascii(*line))) { k--; line++; } /* remove empty lines and comments */ if (line[0] == '#' || line[0] == '\0') { current_line++; continue; } /* execute instruction */ param_string = line; token = Utils::getToken(¶m_string, " \t"); if (token) ret = run(token, param_string, context); else { current_line++; continue; } /* get return value */ switch (ret) { case Interp::BADCOMMAND: case Interp::PARAMPARSINGERROR: case Interp::WRONGPARAMCOUNT: case Interp::PERMISSIONDENIED: sysHandler(token, current_line, ret, context); return FAILURE; default: usrHandler(token, current_line, ret, context); } current_line++; } return SUCCESS; }
/* * Print out a filename (or other ascii string). * Return true if truncated. */ int printfn(u_char *s, u_char *ep) { u_char c; putchar('"'); while ((c = *s++) != 0) { if (s > ep) { putchar('"'); return (1); } if (!isascii(c)) { c = toascii(c); putchar('M'); putchar('-'); } if (!isprint(c)) { c ^= 0x40; /* DEL to ?, others to alpha */ putchar('^'); } putchar(c); } putchar('"'); return (0); }
int dns_name_element(BSB *nbsb, BSB *bsb) { int nlen = 0; BSB_IMPORT_u08(*bsb, nlen); if (nlen == 0 || nlen > BSB_REMAINING(*bsb)) { return 1; } int j; for (j = 0; j < nlen; j++) { register u_char c = 0; BSB_IMPORT_u08(*bsb, c); if (!isascii(c)) { BSB_EXPORT_u08(*nbsb, 'M'); BSB_EXPORT_u08(*nbsb, '-'); c = toascii(c); } if (!isprint(c)) { BSB_EXPORT_u08(*nbsb, '^'); c ^= 0x40; } BSB_EXPORT_u08(*nbsb, c); } return 0; }
static void test_toascii (void) { int i, j; for (i = -127; i < 256; ) j = i, printf ("%s: %d -> %d\n", __FUNCTION__, j, toascii (i++)); }
void main() { char array[100]; int user_input; int a; int point; while(a<100){array[a]='\0';a++;} printf("Please enter your numbers here please\r\n"); gets(array); printf("Please enter the number your looking for \r\n"); scanf("%d",&user_input); a=0; int n=0; while(a<100) { if(array[a]=='1'||array[a]=='2'||array[a]=='3'||array[a]=='4'||array[a]=='5'||array[a]=='6' ||array[a]=='7'||array[a]=='8'||array[a]=='9'||array[a]=='0'){n++;} a++; } //printf("There are %d elements in the array\r\n",n); //printf("A=%d\r\n",a); point=n-user_input; //printf("%d is the point \r\n",point); printf("\n%c is your number\r\n",toascii(digit(array,point)));//as i use a char array //i must convert the integer from the decimal value back to ascii value }
int main(void) { char str[80]; int i; printf("Enter a string: \r\n"); gets(str); for( i = 0; str[ i ]; i++) str[ i ] = toupper( str[ i ] ); printf("%s\n", str); /* uppercase string */ for(i = 0; str[ i ]; i++) str[i] = tolower(str[ i ]); printf("%s\n", str); /* lowercase string */ for(i = 0;str[i];i++) str[i] = toascii(str[i]);/*produces a sum of ascii characters*/ printf("%d\n",str); return 0; }
int main (void) { char c; printf ("Enter the character to test: "); scanf ("%c", &c); printf ("isalpha ('%c') is %s\n", c, isalpha ((int) c) ? "True" : "False"); printf ("isalnum ('%c') is %s\n", c, isalnum ((int) c) ? "True" : "False"); printf ("isascii ('%c') is %s\n", c, isascii ((int) c) ? "True" : "False"); printf ("iscntrl ('%c') is %s\n", c, iscntrl ((int) c) ? "True" : "False"); printf ("isdigit ('%c') is %s\n", c, isdigit ((int) c) ? "True" : "False"); printf ("isgraph ('%c') is %s\n", c, isgraph ((int) c) ? "True" : "False"); printf ("islower ('%c') is %s\n", c, islower ((int) c) ? "True" : "False"); printf ("isprint ('%c') is %s\n", c, isprint ((int) c) ? "True" : "False"); printf ("ispunct ('%c') is %s\n", c, ispunct ((int) c) ? "True" : "False"); printf ("isspace ('%c') is %s\n", c, isspace ((int) c) ? "True" : "False"); printf ("isupper ('%c') is %s\n", c, isupper ((int) c) ? "True" : "False"); printf ("isxdigit ('%c') is %s\n\n", c, isxdigit ((int) c) ? "True" : "False"); printf ("tolower ('%c') gives %c\n", c, tolower ((int) c)); printf ("_tolower ('%c') gives %c\n", c, _tolower ((int) c)); printf ("toupper ('%c') gives %c\n", c, toupper ((int) c)); printf ("_toupper ('%c') gives %c\n", c, _toupper ((int) c)); printf ("toascii ('%c') gives %c\n", c, toascii ((int) c)); return (0); }
/* * Print out a null-terminated filename (or other ascii string). * If ep is NULL, assume no truncation check is needed. * Return true if truncated. */ int fn_print(register const u_char *s, register const u_char *ep, char *buf) { register int ret; register u_char c; ret = 1; /* assume truncated */ while (ep == NULL || s < ep) { c = *s++; if (c == '\0') { ret = 0; break; } if (!isascii(c)) { c = toascii(c); sprintf(&buf[strlen(buf)], "%c", 'M'); sprintf(&buf[strlen(buf)], "%c", '-'); } if (!isprint(c)) { c ^= 0x40; /* DEL to ?, others to alpha */ sprintf(&buf[strlen(buf)], "%c", '^'); } sprintf(&buf[strlen(buf)], "%c", c); } return(ret); }
static packetbody_t c_print(packetbody_t s, packetbody_t ep) { register u_char c; register int flag; flag = 1; while (s < ep) { c = *s++; if (c == '\0') { flag = 0; break; } if (!isascii(c)) { c = toascii(c); putchar('M'); putchar('-'); } if (!isprint(c)) { c ^= 0x40; /* DEL to ?, others to alpha */ putchar('^'); } putchar(c); } if (flag) return NULL; return (s); }
int sfn_print(char* buffer,u_char *s, u_char *ep) { register int ret; u_char c; ret = 1; /* assume truncated */ while (ep == NULL || s < ep) { c = *s++; if (c == '\0') { ret = 0; break; } if (!isascii(c)) { c = toascii(c); sprintf(buffer,"%sM",buffer); sprintf(buffer,"%s-",buffer); } if (!isprint(c)) { c ^= 0x40; /* DEL to ?, others to alpha */ sprintf(buffer,"%s^",buffer); } sprintf(buffer,"%s%s",buffer,&c); } return(ret); }
/* * Print out a null-terminated filename (or other ascii string). * If ep is NULL, assume no truncation check is needed. * Return true if truncated. */ int fn_print(register const u_char *s, register const u_char *ep) { register int ret; register u_char c; ret = 1; /* assume truncated */ while (ep == NULL || s < ep) { c = *s++; if (c == '\0') { ret = 0; break; } if (!isascii(c)) { c = toascii(c); putchar('M'); putchar('-'); } if (!isprint(c)) { c ^= 0x40; /* DEL to ?, others to alpha */ putchar('^'); } putchar(c); } return(ret); }
static void cook_cat(FILE *fp) { int ch, gobble, line, prev; /* Reset EOF condition on stdin. */ if (fp == stdin && feof(stdin)) clearerr(stdin); line = gobble = 0; for (prev = '\n'; (ch = getc(fp)) != EOF; prev = ch) { if (prev == '\n') { if (sflag) { if (ch == '\n') { if (gobble) continue; gobble = 1; } else gobble = 0; } if (nflag && (!bflag || ch != '\n')) { (void)fprintf(stdout, "%6d\t", ++line); if (ferror(stdout)) break; } } if (ch == '\n') { if (eflag && putchar('$') == EOF) break; } else if (ch == '\t') { if (tflag) { if (putchar('^') == EOF || putchar('I') == EOF) break; continue; } } else if (vflag) { if (!isascii(ch) && !isprint(ch)) { if (putchar('M') == EOF || putchar('-') == EOF) break; ch = toascii(ch); } if (iscntrl(ch)) { if (putchar('^') == EOF || putchar(ch == '\177' ? '?' : ch | 0100) == EOF) break; continue; } } if (putchar(ch) == EOF) break; } if (ferror(fp)) { warn("%s", filename); rval = 1; clearerr(fp); } if (ferror(stdout)) err(1, "stdout"); }
void mno_alph::encrypt() { strcpy(strtext," "); strcpy(strcode," "); len=0; cout<<"enter key "<<endl; for(i=0;i<=25;++i) { lettertext[i]=toascii(i+97); cout<<"enter key for "<<lettertext[i]; cin>>key[i]; } cout<<"Enter text "<<endl; cin>>strtext; len=strlen(strtext); for(i=0;i<=len-1;++i) { for(j=0;j<=25;++j) { if(strtext[i]==lettertext[j]) { strcode[i]=key[j]; } } } cout<<"code= "<<strcode<<endl; }
const u_char * c_print(register const u_char *s, register const u_char *ep) { register u_char c; register int flag; flag = 1; while (ep == NULL || s < ep) { c = *s++; if (c == '\0') { flag = 0; break; } if (!isascii(c)) { c = toascii(c); putchar('M'); putchar('-'); } if (!isprint(c)) { c ^= 0x40; /* DEL to ?, others to alpha */ putchar('^'); } putchar(c); } if (flag) return NULL; return (s); }
int main(int argc, const char * argv[]) { FILE *file = fopen(argv[1], "r"); char line[1024]; while (fgets(line, 1024, file)) { int i = 0; bool empty = true; while (line[i]) { if (line[i] >= 'a' && line[i] <= 'j') { printf("%d", toascii(line[i]) - 97); empty = false; } if (line[i] >= '0' && line[i] <= '9') { empty = false; printf("%c", line[i]); } i++; } if (empty) printf("NONE"); printf("\n"); } return 0; }
Pixel Orc::render(float luma) { Pixel p; p.fg = makeColor(2,2,2); p.bg = 0; p.a = 0; p.c = toascii('O'); return p; }
void get_random(char outstring[],int count) { int i=0,base=126-32; //get printable ascii character between 32-126 for(i=0;i<count-1;i++) outstring[i]=toascii((rand()%base)+32); outstring[i]='\0'; }
void ServerItem::convert(char *l) { if (strcmp(mode, "netascii") != 0) return; while (*l != 0) { *l = toascii(*l); l++; } }
int main() { //将整形数转换成合法的ASCII码字符 int a = 217; char b; printf("before toascii() : a value =%d(%c)\n",a,a); b=toascii(a); printf("after toascii() : a value =%d(%c)\n",b,b); }
void jkfprintf(FILE *tp, char name[], off_t offset) { char *cp, ch; char visout[5], *s2; FILE *fi; int linecnt, charcnt, inheader; char line[BUFSIZ]; if ((fi = fopen(name, "r")) == NULL) return; (void)fseeko(fi, offset, SEEK_SET); /* * Print the first 7 lines or 560 characters of the new mail * (whichever comes first). Skip header crap other than * From, Subject, To, and Date. */ linecnt = 7; charcnt = 560; inheader = 1; while (fgets(line, sizeof(line), fi) != NULL) { if (inheader) { if (line[0] == '\n') { inheader = 0; continue; } if (line[0] == ' ' || line[0] == '\t' || (strncmp(line, "From:", 5) && strncmp(line, "Subject:", 8))) continue; } if (linecnt <= 0 || charcnt <= 0) { (void)fprintf(tp, "...more...%s", cr); (void)fclose(fi); return; } /* strip weird stuff so can't trojan horse stupid terminals */ for (cp = line; (ch = *cp) && ch != '\n'; ++cp, --charcnt) { ch = toascii(ch); vis(visout, ch, VIS_SAFE|VIS_NOSLASH, cp[1]); for (s2 = visout; *s2; s2++) (void)fputc(*s2, tp); } (void)fputs(cr, tp); --linecnt; } (void)fprintf(tp, "----%s\n", cr); (void)fclose(fi); }
int main(void) { int i = 8; int j = 5; double x = 0.005, y = -0.01; char c = 'c', d = 'd'; // Absolute value of integer printf("a) %d \n", abs(i - 2 * j)); // Absolute value of floating point number printf("b) %f \n", fabs(x+y)); // 1-0, printable or not printf("c) %d \n", isprint(c)); // 1-0, parameter is decimal digit or not printf("d) %d \n", isdigit(c)); // Convert form lowercase to uppercase printf("e) %d \n", toupper(d)); // Round upwards printf("f) %f \n", ceil(x)); // Round updwards printf("g) %f \n", ceil(x+y)); // Round downwards printf("h) %f \n", floor(x)); // Round downwards printf("i) %f \n", floor(x+y)); // 1-0, lowercase letter or not printf("j) %d \n", islower(c)); // 1-0 is uppercase letter or not printf("k) %d \n", isupper(j)); // Base e exponential function, e^x printf("l) %f \n", exp(x)); // Natural logarithm printf("m) %f \n", log(exp(x))); // Square root printf("o) %f \n", sqrt(x*x+y*y)); // 1-0, is dedimal digit or letter printf("p) %d \n", isalnum(10*j)); //1-0, is alphabetic letter or not printf("q) %d \n", isalpha(10*j)); // 1-0, ascii or not printf("r) %d \n", isascii(10*j)); // Converts to ascii printf("s) %d \n", toascii(10*j)); // Floating point remainder of x/y printf("t) %f \n", fmod(x,y)); // Converts to lowercase if a letter printf("u) %d \n", tolower(65)); // Length of string before termination printf("v) %zu \n", strlen("hello\0")); // WTF //printf("w) %d \n", strpos("hello\0", 'e')); }
/**********************СОРТИРОВКА ПО ДЛИНЕ***************************/ void length(void) { FILE *f,*f1; char filename[14],nameoffile[14]; char c; int i,n=0,k; instr com; window(1,1,80,25); textbackground(0); textcolor(2); clrscr(); cputs("Введите имя файла-источника данных..."); scanf("%s",filename); cputs("Введите имя файла,в который будут записаны данные..."); scanf("%s",nameoffile); f=fopen(filename,"r"); f1=fopen(nameoffile,"aw"); fseek(f,0,SEEK_SET); while(!feof(f)) { fread(&com,sizeof(com),1,f); n++; } printf("Мнемокод Длина Машинный код\n"); n--; for(k=49;k<=57;k++) { fseek(f,0,SEEK_SET); for(i=0;i<n;i++) { c=toascii(k); fread(&com.name,sizeof(com.name),1,f); fread(&com.size,sizeof(com.size),1,f); fread(&com.hex,sizeof(com.hex),1,f); if(com.size[0]==c) { fwrite(&com,sizeof(com),1,f1); printf("%s",&com.name); gotoxy(15,wherey()); printf("%s",&com.size); gotoxy(18,wherey()); printf("%s\n",com.hex); } } } fcloseall(); cputs("Обработка завершена..."); getch(); }
/** * @brief * Given a string str, converts instances of ' ' (space) with the repl string. * Also, if the first character in repl string appears in str, then that is * replaced with '%<hex_num>' where <hex_num> is the ascii hex represetation of * that character. * * This returns a statically allocated area. * For example, the function call * "replace_space("ap%ple banana", "%20") * results in ap%25ple%20banana * for %25 = %, and %20 = <space>. * * Special Case: if rep string is given as "", then the returned string will * be quoted if a space character is found. */ char * replace_space(char *str, char *repl) { static char rstr[512]; static char rstr2[512]; int i, j; int repl_len; char spec_chars[4]; char spec_len; int has_space = 0; if (str == NULL || repl == NULL) return NULL; repl_len = strlen(repl); sprintf(spec_chars, "%%%02d", toascii(repl[0])); spec_len = strlen(spec_chars); i = 0; while (*str != '\0') { if (*str == repl[0]) { for (j=0; j< spec_len; j++, i++) { rstr[i] = spec_chars[j]; } } else if (*str == ' ' && repl_len > 0) { for (j=0; j< repl_len; j++, i++) { rstr[i] = repl[j]; } } else { rstr[i] = *str; i++; } if (*str == ' ') has_space = 1; str++; } rstr[i] = '\0'; if (repl_len == 0 && has_space) { sprintf(rstr2, "\"%s\"", rstr); return (rstr2); } return (rstr); }
/* * Convert a character to displayable format, returns true when we fill a * display-line. */ static int typeconv(int c) { char dot = (char) (OptStripped ? ' ' : '.'); if (OptBinary) { /* highlight chars with parity */ if (!isascii(c)) { c = toascii(c); if (OptStripped) { if (!isprint(c)) c = ' '; } else if (Tcol < (int) END_COL) Text[Tcol] = '_'; } } if (isascii(c)) { if (OptBinary && !isprint(c)) { typeover(dot); } else if (c == '\b') { if (Tcol > 0) Tcol--; } else if (c == '\r') { Tcol = 0; } else if (isprint(c)) { typeover(c); } else if (isspace(c)) { if (c == '\n') { while (Tlen > 0 && isspace(UCH(Text[Tlen - 1]))) Tlen--; return (TRUE); } else if (c == '\t') { typeover(' '); while (Tcol % tabstop) typeover(' '); } } else { typeover(dot); } } else if (OptBinary) { typeover(dot); } if (OptBinary) if (Tlen - Shift >= COLS) return (TRUE); return (FALSE); }
/* Function Name: ui_calculateHashIndex Description: It takes the fileName to be hashed and calculates the hash index for the hash table. Parameters: It takes the fileName as the parameter Return Type: It returns the hash index */ unsigned int ui_calculateHashIndex(char *fileName){ char c_firstCharacter = '\0'; unsigned int ui_index = 0; c_firstCharacter = *fileName; ui_index = toascii(toupper(c_firstCharacter)); ui_index = ui_index - 65; if(ui_index < 0 || ui_index > 25){ ui_index = 26; } return ui_index; }
void hexdump(unsigned char *buf, int nbytes) { int i, j; for (i = 0; i < nbytes; i += 16) { printf("%04X : ", i); for (j = 0; j < 16 && i + j < nbytes; j++) printf("%2.2X ", buf[i + j]); for (; j < 16; j++) { printf(" "); } printf(": "); for (j = 0; j < 16 && i + j < nbytes; j++) { char c = toascii(buf[i + j]); printf("%c", isalnum(c) ? c : '.'); } printf("\n"); } }
static void vputc(unsigned char ch) { int meta; if (!isprint(ch) && !isascii(ch)) { (void)putchar('M'); (void)putchar('-'); ch = toascii(ch); meta = 1; } else meta = 0; if (isprint(ch) || (!meta && (ch == ' ' || ch == '\t' || ch == '\n'))) (void)putchar(ch); else { (void)putchar('^'); (void)putchar(ch == '\177' ? '?' : ch | 0100); } }
int main(void) { char c; puts("Give me a char"); c = getchar(); putchar('\n'); /* Start the comparision */ printf("%c %s an alpha character (%u)\n", c, isalpha((int)c) ? "is" : "is not", isalpha((int)c)); printf("%c %s an upper character (%u)\n", c, isupper((int)c) ? "is" : "is not", isupper((int)c)); printf("%c %s a lower character (%u)\n", c, islower((int)c) ? "is" : "is not", islower((int)c)); printf("%c %s a digit character (%u)\n", c, isdigit((int)c) ? "is" : "is not", isdigit((int)c)); printf("%c %s a hex digit character (%u)\n", c, isxdigit((int)c) ? "is" : "is not", isxdigit((int)c)); printf("%c %s an alnum character (%u)\n", c, isalnum((int)c) ? "is" : "is not", isalnum((int)c)); printf("%c %s a space character (%u)\n", c, isspace((int)c) ? "is" : "is not", isspace((int)c)); printf("%c %s a punctuation character (%u)\n", c, ispunct((int)c) ? "is" : "is not", ispunct((int)c)); printf("%c %s a printer character (%u)\n", c, isprint((int)c) ? "is" : "is not", isprint((int)c)); printf("%c %s a graphic character (%u)\n", c, isgraph((int)c) ? "is" : "is not", isgraph((int)c)); printf("%c %s a control character (%u)\n", c, iscntrl((int)c) ? "is" : "is not", iscntrl((int)c)); printf("%c %s a blank character (%u)\n", c, isblank((int)c) ? "is" : "is not", isblank((int)c)); printf("%c %s an ASCII character (%u)\n", c, isascii((int)c) ? "is" : "is not", isascii((int)c)); printf("%c to upper is %c\n", c, toupper((int)c)); printf("%c to lower is %c\n", c, tolower((int)c)); printf("%c to ASCII is %c\n", c, toascii((int)c)); return 0; } /* E0F main */
int main() { char str[100]; int l,flag,asciiflag,i,c_flag; level: while((scanf("%s",str))){ if(strcmp(str,"end")==0) break; flag=0; asciiflag=0; c_flag=0; l=strlen(str); for(i=0;i<l;i++) { if(str[i]=='a'||str[i]=='e'||str[i]=='i'||str[i]=='o'||str[i]=='u') { flag++; } if(str[i]==str[i-1]) { c_flag++; if(c_flag>1){ printf("<%s> is not acceptable.\n",str); goto level; } } if(str[i]==toascii(str[i])+1) { asciiflag++; if(asciiflag==2) { printf("<%s> is not acceptable.\n",str); goto level; } } } if(flag>0&&c_flag==0&&asciiflag<2) printf("<%s> is acceptable.\n",str); else printf("<%s> is not acceptable.\n",str); } return 0; }
/* * Print out a counted filename (or other ascii string). * If ep is NULL, assume no truncation check is needed. * Return true if truncated. */ int fn_printn(register const u_char *s, register u_int n, register const u_char *ep) { register u_char c; while (n > 0 && (ep == NULL || s < ep)) { n--; c = *s++; if (!isascii(c)) { c = toascii(c); putchar('M'); putchar('-'); } if (!isprint(c)) { c ^= 0x40; /* DEL to ?, others to alpha */ putchar('^'); } putchar(c); } return (n == 0) ? 0 : 1; }