Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Detect String In C Code.

Amirul AmirAmirul Amir Member Posts: 3

** What i'm trying to do is to check the user input from string. If the user input matched with IS or GM it'll print a message. But the problem in this code is it only detect the first character. Example => I instead of IS. **

#include <stdio.h>
int student_verify();
void displayOutput(char);

int main(void)
{
    char select;
    select = student_verify();
    displayOutput(select);

    return(0);
}

void displayOutput(char select)
{   
    if (select == 'IS')
    {
        printf("\nIS Student");
    }
    else if (select == 'GM')
    {
        printf("\nGM Student");
    }
}

int student_verify()
{
    char user_id[20];
    char i;
    i = user_id[20];

    printf("Enter Your Student ID Code:");
    scanf("%c", &i);

    return i;
}

Comments

Sign In or Register to comment.