Строка в качестве аргумента для указателя на функцию - PullRequest
0 голосов
/ 24 января 2019

Приведенная ниже программа не принимает данные во второй итерации цикла for. Пожалуйста, предоставьте мне какое-нибудь решение.

В приведенной ниже программе есть указатели на функции, где строка является вводом указателей на функции.

/ ******* КОД ******* /

#include<stdio.h>
#include<conio.h>
#include<string.h>
#define size (100)

int GetName(char *str_Name)
{
    printf("\n Name of the Employee :%s",str_Name);
    return strlen(str_Name);
}

int GetPlaceName(char *str_Name)
{
    printf("\n Name of the Place :%s",str_Name);
    return strlen(str_Name);
}

int GetStateName(char *str_Name)
{
    printf("\n Name of the State :%s",str_Name);
    return strlen(str_Name);
}

int main()
{
    char Names[size] = {'\0'},*Ptr_Names;
    int rtn_len,i;
    int (*char_fun_ptr[])(char *str) = {GetName,GetPlaceName,GetStateName};
    printf("\n First Enter 'Your Name', Then Enter your 'Place Name' and then Enter your 'State Name'");
    for(i = 0; i < 3; i++)
    {
        printf("\n Enter the Name : ");
        scanf("%[^\n]s",Names);
        Ptr_Names = Names;
        rtn_len = char_fun_ptr[i](Ptr_Names);
        printf("\n Length is :%d",strlen(Names));
        memset(Names,0,size*sizeof(char));
    }
    getch();
    return 0;
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...