嗨,我对语言'C'非常陌生,我正在努力从函数中打印我的返回值,get_type_of_card()我想在同一行的 main 中打印它。如果我输入了字符串“VISA”,那么输出 = VISA。
截至目前,输出只是"VISA"中的'V'。
我有一个警告,我想知道如何摆脱它。
WARNING: assignment makes pointer from integer without a cast [-Wint conversion] card[i] = c;
我尝试了一个 for 循环putchar()。
#include <stdio.h>
#include <ctype.h>
//Function prototypes
const char* get_type_of_card();
int main(void)
{
const char* type_of_crd = get_type_of_card();
printf("\nYou entered: %c", type_of_crd);
return 0;
}
const char* get_type_of_card()
{
const char* card[50];
char c;
int i;
do
{
printf("\nPlease select a credit card: ");
for (i = 0; (c = getchar()) != '\n'; ++i)
{
card[i] = c;
return card[i]; // Holds value of "VISA"
}
card[i] = '\0';
} while ((c != '\n') && (c != EOF));
}