Wednesday 12 September 2012

String002

Input a name and find length, position of character in the string and that name.

#include <stdio.h>
#include <conio.h>

void main ( )
{
          char       nm[80];
          int          i, ln;
          clrscr ( );
             
          printf("\n\t\t Enter a name....:"); gets (nm);
             
          printf("\n\n\n\t\t NAME....:");
          for ( ln = 0; nm[ln] != '\0'; ln++)
          {                                  
                       printf("%c ", nm[ln]);
          }                          
          printf("\n\n\n\t\t Length of name.......: %d\n\n", ln);
                                                      
          for ( i = 0; i < ln; i++ )
          {                          
                       printf("\n\t\t Character = %c at Position = %2d", nm[i], i );
          }
          getch ( );
}
Click here to contact us

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...