I get the error: "cast to smaller integer type 'int' from 'string' (aka 'char *')" referencing line of code: while (isalpha(residents[i].name) == 0)

Viewed 48

Please note that the error I am receiving is "cast to smaller integer type 'int' from 'string' (aka 'char *')" referencing line of code: while (isalpha(residents[i].name) == 0). What I am trying to do in that line of code is check to make sure each character in my string is alphabetical.

#include <stdio.h>
#include <cs50.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>

typedef struct
{
    string name;
    int apt;
} tenant;

int main(void)
{
    int n;

    do
    {
        n = get_int("Enter the number of residents: ");
    } while (isalpha(n) != 0 || isspace(n) != 0);

    printf("\n");

    tenant residents[n];

    for (int i = 0; i < n; i++)
    {
        do
        {
            residents[i].name = get_string("Enter the residents name: ");
        } while (isalpha(residents[i].name) == 0)

        do
        {
            residents[i].apt = get_int("Enter the residents apt#: ");
        } while (isalpha(residents[i].apt) != 0);
    }

    printf("\n");

    for (int j = 0; j < n; j++)
    {
        printf("%s resides at %i\n", residents[j].name, residents[j].apt);
    }

    return 1;
}
0 Answers
Related