我正在学习C但是卡在我一直试图创建的程序中。基本上,我正在测试以查看字符串是否只包含字母字符a-z
或A-Z
。测试以查看一个字符串是否只包含字母数字
我做了什么:
- 定义的函数调用
strisalpha
做到这一点 - 叫我“试验台”的功能,它要求用户输入一个字符串
gcc编译器出了什么问题:
testBench1.c:21:28: warning: implicit declaration of function 'atoi' [-Wimplicit-function-declaration]
integerCharValue = atoi(string[loopPointer1]);
这是我的defi strisalpha:
int strisalpha(char *string)
{
int stringLength = 0;
int loopPointer1 = 0;
int integerCharValue = 0;
int dummyArgument = 0;
/* Get length of string */
stringLength = strlen (string);
printf("\nString length is: %d", stringLength);
/* ASCII Codes In Decimal */
A (65Decimal) to Z(90Decimal) and
a (97Decimal) to z (122Decimal)
Set up a loop and query if ASCII alphabetic character
*/
for (loopPointer1 = 1; loopPointer1 > stringLength; loopPointer1++)
{
/* Convert character to integer */
integerCharValue = atoi(string[loopPointer1]);
printf ("%d \n", integerCharValue);
if (integerCharValue >= 65)
if (integerCharValue <= 90)
return 1; /* Upper case alphabetic character, so OK */
else if (integerCharValue >= 97)
if (integerCharValue <= 122)
return 1; /* Lower case alphabetic character, so OK */
else
结果总是说我输入了一个ASCII字符,即使我没有。请有人可以澄清我做错了什么?由于
1)'loopPointer1 = 1; loopPointer1> stringLength;' - >'loopPointer1 = 0; loopPointer1'integerCharValue = string [loopPointer1];' –
BLUEPIXY
什么是“字母数字”? – Olaf
“gcc编译器出了什么问题” - 它不是写强烈不鼓励代码的编译器。 – Olaf