我试图将字符串中的每个字母转换为其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
允许我使用“string
”而不是“char*
”。