Learning C++: Finding length of string in C ? (Not for C++ Readers)

Pages

Wednesday, August 24, 2011

Finding length of string in C ? (Not for C++ Readers)

In below program, I have find out string length and print each character of string in new line..

#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
 char string[10];
 int i=0,lengh=0;
 clrscr();

 printf("Enter the string: ");
 scanf("%s",&string);
 lengh=strlen(string);

 for(i=0;i<lengh;i++)
 {
 printf("%c",string[i]);
 printf("\n");
 }
 getch();
}

No comments:

Post a Comment