You must Sign In to post a response.
  • Category: Programming

    Want a C program which gives initials of person when full name of person is given.


    Having difficulty in writing a C program? Searching for solution to a problem? find advice from experts here and understand how to write any C program.

    I just want a C program which gives initials of person when full name of person is given. This question is asked to my friend in an interview. Suppose input given to the program is Ajay Vijay Rane, the program will expected to return the output as A.V.R. which are initials of the person.
    I am sure quality response will be given by experts of ISC.
  • #152537
    You can try the programme, which I have tried for some other purpose.
    C program which will print the initial character of each string. In which we use the character array.

    For Example:
    if we take input from the user: "Ajay Vijay Rane "
    there is three string value and the Initial character of each string is AVR

    ALGORITHM:-
    step 1 : Start
    step 2 : Take an character array
    step 3 : Take the input from user
    step 4 : While(string[i]!='')
    step 5 : If [i]th value is ' '(space) then the print the i+1 character
    step 6 : Exit
    PROGRAM CODE:-
    #include
    #include
    int main()
    {
    char str[20];
    int i=0;
    printf("Enter a string: ");
    gets(str);
    printf("%c", *str);
    while(str[i] != '')
    {
    if(str[i] == ' ')
    {
    i++;
    printf("%c", *(str + i));
    }
    i++;
    }
    return 0;
    }
    OUTPUT:-

    drrao
    always confident

  • #152543
    TThis response is marked as DELETED by the admin.

    Error - Please Ignore

  • #152544
    I executed below program in the shell and got the output as desired, you can also try the below solution- (attaching the screenshot of the program

    How to execute above program:
    gcc name.c -o name (This will compile and generate a file with the name "name")
    ./name (this will execute the generated file and will ask you to enter the name)

    After you execute it will ask for the string and it will give the desired output.

    Please note that while you compile the above program it will give an error "warning: the `gets' function is dangerous and should not be used." You can ignore this warning.

    Delete Attachment

  • #152559
    TThis response is marked as DELETED by the admin.

    Great post, Thank you very much. Am impressed.
    Top School News


  • Sign In to post your comments