默難 回復于:2005-02-10 18:53:00 |
isdigit |
akaaron 回復于:2005-02-10 19:56:59 |
具體一點,好嗎?我才開始學....
說出來我不能理解沒有關系.我會努力去理解的... |
akaaron 回復于:2005-02-10 20:25:02 |
沒人幫忙嗎?我換了好多方法都不行....先將輸入的值賦給一個數組,再對數組內的值進行判斷.也不行.誰能幫幫我呀.... |
默難 回復于:2005-02-10 20:28:59 |
你要的程序是不是:
要求用戶輸入N個數,輸出其中最大的數 對不對? |
默難 回復于:2005-02-10 20:52:04 |
[quote:a05949336a="akaaron"]沒人幫忙嗎?我換了好多方法都不行....先將輸入的值賦給一個數組,再對數組內的值進行判斷.也不行.誰能幫幫我呀....[/quote:a05949336a]
如果輸入一個子母,實際也就是輸入了一個數字…… 你可以做的就是從標準輸入按照字符串的形式讀入,然后用isdigit檢驗~ |
kert_t8 回復于:2005-02-11 04:27:48 |
ISALPHA(3) Linux Programmer's Manual ISALPHA(3)
NAME isalnum, isalpha, isascii, isblank, iscntrl, isdigit, isgraph, islower, isprint, ispunct, isspace, isupper, isxdigit - character classification routines SYNOPSIS #include <ctype.h> int isalnum(int c); int isalpha(int c); int isascii(int c); int isblank(int c); int iscntrl(int c); int isdigit(int c); int isgraph(int c); int islower(int c); int isprint(int c); int ispunct(int c); int isspace(int c); int isupper(int c); int isxdigit(int c); DESCRIPTION These functions check whether c, which must have the value of an unsigned char or EOF, falls into a certain character class aclearcase/" target="_blank" >ccording to the current locale. isalnum() checks for an alphanumeric character; it is equivalent to (isalpha(c) || isdigit(c)). isalpha() checks for an alphabetic character; in the standard "C" locale, it is equivalent to (isupper(c) || islower(c)). In some locales, there may be additional characters for which isalpha() is true--letters which are neither upper case nor lower case. isascii() checks whether c is a 7-bit unsigned char value that fits into the ASCII character set. This function is a BSD extension and is also an SVID extension. isblank() checks for a blank character; that is, a space or a tab. This function is a GNU extension. iscntrl() checks for a control character. isdigit() checks for a digit (0 through 9). isgraph() checks for any printable character except space. islower() checks for a lower-case character. isprint() checks for any printable character including space. ispunct() checks for any printable character which is not a space or an alphanumeric character. isspace() checks for white-space characters. In the "C" and "POSIX" locales, these are: space, form-feed ('\f'), newline ('\n'), carriage return ('\r'), horizontal tab ('\t'), and vertical tab ('\v'). isupper() checks for an uppercase letter. isxdigit() checks for a hexadecimal digits, i.e. one of 0 1 2 3 4 5 6 7 8 9 a b c d e f A B C D E F. RETURN VALUE The values returned are nonzero if the character c falls into the tested class, and a zero value if not. CONFORMING TO ANSI - C, BSD 4.3. isascii() is a BSD extension and is also an SVID extension. isblank() is a GNU extension. NOTE The details of what characters belong into which class depend on the current locale. For example, isupper() will not recognize an A - umlaut as an upper- case letter in the default C locale. SEE ALSO tolower(3), toupper(3), setlocale(3), ascii(7), locale(7) GNU 1995-09-02 ISALPHA(3) |
akaaron 回復于:2005-02-11 07:49:07 |
謝謝...我回去琢磨一下...
雖然對函數的用法還是很模糊.....但知道各個函數的功能.謝謝各位的幫助.,我會查這方面的資料的..... |
akaaron 回復于:2005-02-11 07:52:30 |
原型:extern int isascii(int c);
用法:#include <ctype.h> 功能:判斷字符c是否為ascii碼 說明:當c為ascii碼時,返回非零值,否則返回零。ascii碼指0x00-0x7F之間的字符 舉例: // isascii.c #include <syslib.h> #include <ctype.h> main() { char s[]="文曲星-BJGGV"; int i=12; // length of string s clrscr(); // clear screen textmode(0xE0); // make sure LCD mode is 3 big line printf("%s\n",s); for(i=0;i<12;i++) { if(isascii(s[i])) putchar('^'); else putchar('.'); } getchar(); return 0; } 相關函數:無 |
akaaron 回復于:2005-02-11 07:53:41 |
原型:extern int isalnum(int c);
用法:#include <ctype.h> 功能:判斷字符c是否為字母或數字 說明:當c為數字0-9或字母a-z及A-Z時,返回非零值,否則返回零。 舉例: // isalnum.c #include <syslib.h> #include <ctype.h> main() { int c; clrscr(); // clear screen c='a'; printf("%c:%s\n",c,isalnum(c)?"yes":"no"); c='7'; printf("%c:%s\n",c,isalnum(c)?"yes":"no"); c='@'; printf("%c:%s\n",c,isalnum(c)?"yes":"no"); getchar(); return 0; } 相關函數:isalpha,isdigit,isxdigit,iscntrl,isgraph,isprint,ispunct,isspace |
akaaron 回復于:2005-02-11 07:54:39 |
原型:extern int isalpha(int c);
用法:#include <ctype.h> 功能:判斷字符c是否為英文字母 說明:當c為英文字母a-z或A-Z時,返回非零值,否則返回零。 舉例: // isalpha.c #include <syslib.h> #include <ctype.h> #include <stdio.h> main() { int c; clrscr(); // clear screen printf("Press a key"); for(;;) { c=getchar(); clrscr(); printf("%c: %s letter",c,isalpha(c)?"is":"not"); } return 0; // just to avoid warnings by compiler } 相關函數:isalnum,isdigit,isxdigit,iscntrl,isgraph,isprint,ispunct,isspace |
akaaron 回復于:2005-02-11 07:55:02 |
原型:extern int iscntrl(int c);
用法:#include <ctype.h> 功能:判斷字符c是否為控制字符 說明:當c在0x00-0x1F之間或等于0x7F(DEL)時,返回非零值,否則返回零。 舉例: // iscntrl.c #include <syslib.h> #include <ctype.h> main() { int c; clrscr(); // clear screen c='a'; printf("%x:%s\n",c,iscntrl(c)?"yes":"no"); c=0x0d; printf("%x:%s\n",c,iscntrl(c)?"yes":"no"); c=0x7f; printf("%x:%s\n",c,iscntrl(c)?"yes":"no"); getchar(); return 0; } 相關函數:isalnum,isalpha,isdigit,isxdigit,isgraph,isprint,ispunct,isspace |
akaaron 回復于:2005-02-11 07:55:45 |
原型:extern int isdigit(int c);
用法:#include <ctype.h> 功能:判斷字符c是否為數字 說明:當c為數字0-9時,返回非零值,否則返回零。 舉例: // isdigit.c #include <syslib.h> #include <ctype.h> main() { int c; clrscr(); // clear screen c='a'; printf("%c:%s\n",c,isdigit(c)?"yes":"no"); c='9'; printf("%c:%s\n",c,isdigit(c)?"yes":"no"); c='*'; printf("%c:%s\n",c,isdigit(c)?"yes":"no"); getchar(); return 0; } 相關函數:isalnum,isalpha,isxdigit,iscntrl,isgraph,isprint,ispunct,isspace |
akaaron 回復于:2005-02-11 07:56:14 |
原型:extern int islower(int c);
用法:#include <ctype.h> 功能:判斷字符c是否為小寫英文字母 說明:當c為小寫英文字母(a-z)時,返回非零值,否則返回零。 舉例: // islower.c #include <syslib.h> #include <ctype.h> main() { int c; clrscr(); // clear screen c='a'; printf("%c:%s\n",c,islower(c)?"yes":"no"); c='A'; printf("%c:%s\n",c,islower(c)?"yes":"no"); c='7'; printf("%c:%s\n",c,islower(c)?"yes":"no"); getchar(); return 0; } 相關函數:isupper |
akaaron 回復于:2005-02-11 07:56:44 |
原型:extern int isgraph(int c);
用法:#include <ctype.h> 功能:判斷字符c是否為除空格外的可打印字符 說明:當c為可打印字符(0x21-0x7e)時,返回非零值,否則返回零。 舉例: // isgraph.c #include <syslib.h> #include <ctype.h> main() { int c; clrscr(); // clear screen c='a'; printf("%c:%s\n",c,isgraph(c)?"yes":"no"); c=' '; // 0x20 printf("%c:%s\n",c,isgraph(c)?"yes":"no"); c=0x7f; printf("%c:%s\n",c,isgraph(c)?"yes":"no"); getchar(); return 0; } 相關函數:isprint |
akaaron 回復于:2005-02-11 07:57:36 |
原型:extern int isprint(int c);
用法:#include <ctype.h> 功能:判斷字符c是否為可打印字符(含空格) 說明:當c為可打印字符(0x20-0x7e)時,返回非零值,否則返回零。 舉例: // isprint.c #include <syslib.h> #include <ctype.h> main() { int c; clrscr(); // clear screen c='a'; printf("%c:%s\n",c,isprint(c)?"yes":"no"); c=' '; printf("%c:%s\n",c,isprint(c)?"yes":"no"); c=0x7f; printf("%c:%s\n",c,isprint(c)?"yes":"no"); getchar(); return 0; } 相關函數:isgraph |
akaaron 回復于:2005-02-11 07:57:53 |
原型:extern int ispunct(int c);
用法:#include <ctype.h> 功能:判斷字符c是否為標點符號 說明:當c為標點符號時,返回非零值,否則返回零。 標點符號指那些既不是字母數字,也不是空格的可打印字符。 舉例: // ispunct.c #include <syslib.h> #include <ctype.h> #include <string.h> main() { char s[]="Hello, Rain!"; int i; clrscr(); // clear screen printf("%s\n",s); for(i=0;i<strlen(s);i++) { if(ispunct(s[i])) printf("^"); else printf("."); } getchar(); return 0; } 相關函數:isalnum,isalpha,isdigit,isxdigit,iscntrl,isgraph,isprint,isspace |
akaaron 回復于:2005-02-11 07:58:30 |
原型:extern int isspace(int c);
用法:#include <ctype.h> 功能:判斷字符c是否為空白符 說明:當c為空白符時,返回非零值,否則返回零。 空白符指空格、水平制表、垂直制表、換頁、回車和換行符。 舉例: // isspace.c #include <syslib.h> #include <ctype.h> main() { char s[]="Test Line 1\tend\nTest Line 2\r"; int i; clrscr(); // clear screen for(i=0;i<strlen(s);i++) { if(isspace(s[i])) putchar('.'); else putchar(s[i]); } getchar(); return 0; } 相關函數:isalnum,isalpha,isdigit,isxdigit,iscntrl,isgraph,isprint,ispunct |
akaaron 回復于:2005-02-11 07:58:50 |
原型:extern int isupper(int c);
用法:#include <ctype.h> 功能:判斷字符c是否為大寫英文字母 說明:當c為大寫英文字母(A-Z)時,返回非零值,否則返回零。 舉例: // isupper.c #include <syslib.h> #include <ctype.h> main() { int c; clrscr(); // clear screen c='a'; printf("%c:%s\n",c,isupper(c)?"yes":"no"); c='A'; printf("%c:%s\n",c,isupper(c)?"yes":"no"); c='7'; printf("%c:%s\n",c,isupper(c)?"yes":"no"); getchar(); return 0; } 相關函數:islower |
akaaron 回復于:2005-02-11 07:59:19 |
原型:extern int isxdigit(int c);
用法:#include <ctype.h> 功能:判斷字符c是否為十六進制數字 說明:當c為A-F,a-f或0-9之間的十六進制數字時,返回非零值,否則返回零。 舉例: // isxdigit.c #include <syslib.h> #include <ctype.h> main() { int c; clrscr(); // clear screen c='a'; printf("%c:%s\n",c,isxdigit(c)?"yes":"no"); c='9'; printf("%c:%s\n",c,isxdigit(c)?"yes":"no"); c='*'; printf("%c:%s\n",c,isxdigit(c)?"yes":"no"); getchar(); return 0; } 相關函數:isalnum,isalpha,isdigit,iscntrl,isgraph,isprint,ispunct,isspace |
akaaron 回復于:2005-02-11 08:00:02 |
原型:extern int toascii(int c);
用法:#include <ctype.h> 功能:將字符c轉換為ascii碼 說明:toascii函數將字符c的高位清零,僅保留低七位。返回轉換后的數值。 舉例: // toascii.c #include <syslib.h> #include <ctype.h> main() { char s[]="文曲星-BJGGV"; int i=12; // length of string s clrscr(); // clear screen textmode(0xE0); // make sure LCD mode is 3 big line printf("%s\n",s); for(i=0;i<12;i++) { putchar(toascii(s[i])); } getchar(); return 0; } 相關函數:無 |
akaaron 回復于:2005-02-11 08:00:23 |
原型:extern int tolower(int c);
用法:#include <ctype.h> 功能:將字符c轉換為小寫英文字母 說明:如果c為大寫英文字母,則返回對應的小寫字母;否則返回原來的值。 舉例: // tolower.c #include <syslib.h> #include <ctype.h> main() { char *s="Hello, World!"; int i; clrscr(); // clear screen printf("%s\n",s); for(i=0;i<strlen(s);i++) { putchar(tolower(s[i])); } getchar(); return 0; } 相關函數:toupper |
akaaron 回復于:2005-02-11 08:00:40 |
原型:extern int toupper(int c);
用法:#include <ctype.h> 功能:將字符c轉換為大寫英文字母 說明:如果c為小寫英文字母,則返回對應的大寫字母;否則返回原來的值。 舉例: // toupper.c #include <syslib.h> #include <ctype.h> main() { char *s="Hello, World!"; int i; clrscr(); // clear screen printf("%s\n",s); for(i=0;i<strlen(s);i++) { putchar(toupper(s[i])); } getchar(); return 0; } 相關函數:tolower |
akaaron 回復于:2005-02-11 08:01:14 |
我把我找到的資料貼出來了...方便大家查詢......謝謝各位的幫助... |
sinboy2002 回復于:2005-02-28 22:54:23 |
辛苦akaaron兄了 |
Benson_linux 回復于:2005-04-06 00:32:10 |
:shock:
提供一個我自己編的函數來控制輸入的類型: int P_p(char get[20]) { int a, b; int back = 0; int i,j = 0; int n[20]; for (i = 0; get[i] != '\0'; i++) { if ((a = (get[i]-48>=0))&&(b = (get[i]-48<=9))) { n[j++] = (get[i]-48); } else { return (0); } } n[j] = -1; j = 0; while (n[j] != -1) { back = back*10+n[j]; j++; } return back; } 讓你主函數中的scanf函數這樣寫:scanf("%s", p); char *p = (char *)malloc(20); 然后調用在main()中這樣調用: scanf("%s",p); while ( !(choice = P_p(p))) { printf("/***Error***/Enter error!\n"); printf("What do you want to do?"); scanf("%s",p); } |
flyer_8601 回復于:2005-04-06 14:29:32 |
程序本身就不正確,const int max=2;
int no[max]; 你定義的no數組長度只有2,你卻往里面放3個數 |