Hi I am very new to the language 'C' I am struggling to print my returned value from the function get_type_of_card()
I would like to print it in main on the same line. If I entered in the string "VISA" then the output = VISA.
As of right now the output is just 'V' out of "VISA".
I have one warning I was wondering how to get rid of it.
WARNING: assignment makes pointer from integer without a cast [-Wint conversion] card[i] = c;
I have tried a for loop with 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));
}