我正在尝试将字符串中的每个字母转换为它的 ASCII 数字。使用
int letter = (atoi(ptext[i]));
给我这个错误:
error: incompatible integer to pointer conversion
passing 'char' to parameter of type 'const char *'; take the
address with & [-Werror]
int letter = (atoi(ptext[i]));
^~~~~~~~
&
/usr/include/stdlib.h:148:32: note: passing argument to parameter
'__nptr' here
extern int atoi (__const char *__nptr)
以下是我可能相关的其余代码:
#include <cs50.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
int main(int argc, string argv[])
{
printf("Give a string to cipher:\n");
string ptext = GetString();
int i = 0;
if (isupper(ptext[i]))
{
int letter = (atoi(ptext[i]));
}
}
我做错了什么,我该如何解决这个问题,以便将字符串转换为 ASCII 值?
注意:cs50.h
让我在 main 中使用“ string
”而不是“ char*
”。