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

  • #152957
    //PROGRAM TO CONVERT GIVEN FULL NAME INTO ITS INITIALS
    #include
    #include
    void main(void)
    {
    char * str;

    char * s;
    char ini[30];
    int i=0,j=0;
    clrscr();
    printf("Enter your full name\n");
    scanf("%[^\n]",str);
    printf("\nEntered name is %s",str);
    s=str;


    ini[i]=*s;
    i++;
    ini[i]='.';
    i++;

    while(*s!='\0')
    {
    if(*s==' ')
    {
    ini[i]=*(++s);
    i++;
    ini[i]='.';
    i++;
    }

    s++;
    }
    ini[i]='\0';
    printf("\nInitials for name %s are %s",str,ini);

    getch();
    }

    Please include header files stdio.h and conio.h in the above code. In above code I used two character pointers. First character pointer *str is used to accept any length string with white spaces in between. To accept string with white spaces we include special character called as circumflex character denoted by (^). When compiler found ^ with a character like [^\n] it means it accepts anything before the character \n(here in this example).
    Hope you will be satisfied with this answer.


  • Sign In to post your comments