Program to Calculate Length of a String (without using strlen in-built function).
#include#include void main(){ char *str; int count = 0,i; clrscr(); printf("\nEnter the String: "); gets(str); for(i=0;str[i]!='\0';i++){ count++; } printf("\nThe length of the string is %d.",count); getch(); }
Output:
Enter the String: Learn C Online
The length of the string is 14.
In ‘\0’ condition the program is not terminating,,its counting ‘\0’ also and giving the result
how to count the word
give pgm for me
in calculating the length of the string do ‘\0’ also counts????
doont no might be not
No \o (NULL char. ) is not counted or might is not useful for this program 😀
instead of char *str you must put char str[ ]
is it ok to replace get with scanf?
Ya it is Ok but you can mostly use the gets because of it is easy way to scan a string 😀
how is clrscr();
“clrscr();” what is this?
is this true?
clrscr(); ::is a function which is mainly used for clear the output screen..if you dont write it in your program then the output screen also show your previous output…
nice
Word Count Program
#include
#include
void main(){
char *str;
int count = 0,i;
int WordCount=1;
clrscr();
printf(“\nEnter the String: “);
gets(str);
for(i=0;str[i]!=’\0′;i++){
count++;
if(str[i]==’ ‘)
WordCount++;
}
printf(“\nThe length of the string is %d.”,count);
Printf(“WordCount is:%d”,WordCount);
getch();
}
Output : Enter The String: Hi Hello Everybody
lenth of the string is :19
WordCount is: 3
#include
#include
void main()
{
int count=0,i=0;
char str[20];
clrscr();
printf(“Enter the string:”);
scanf(“%s”,str);
while(str[i]!=’\0′)
{
count++;
i++;
}
printf(“The string length is:%d”,count);
getch();
}
kindly give me a program in string function that could tell if the word is a palindrome.. 🙂
#include
#include
#include
void main()
{
char *st,*ptr;
int i;
clrscr();
printf(“enter the string to scan : “);
gets(st);
strcpy(ptr,st);
strrev(st);
i=strcmp(ptr,st);
if(i==0)
printf(“Entered string is palindrome…”);
printf(“Entered string is not palindrome…”);
getch();
}
clrscr();
is clear the screen before all of the items be printed off or display
#include
#include
void main(){
char *str;
int len,i;
clrscr();
printf(“\nEnter the String: “);
gets(str);
for(i=0;str[i]!=’\0′;i++){
len=i;
}
printf(“\nThe length of the string is %d.”,len);
getch();
}
will this one work fine???
but it code cant accept space value…..string rule ::::string consider a space in string length…
no it will print (n-1) characters ,becoz u taking ‘i’ value initiate with ‘0’ so it will display of length (length-1)
Instead why can’t we use sizeof() function,
like
#include
#include
#include
void main()
{
char str[]=”this is the string time”;
cout<<sizeof(str);
}
write a c program to sort a list of string according to the length of the string in descending order using a two dimensional array. The program will continue accepting string until and unless “END” is typed.The program should have two functions i.e main and another reorder(to arrange the list of string). you cannot use any predefined string functions such as strcmp or strcpy or even strlen.
Sir is that possible that we can make a program which print itself in the function ? :/ :/
Sir i can’t understand the Malloc() & Calloc() is there anyone who tells me abot them with example in a easy way ? :/ :/
hey i want to make a program in c in which it takes input as a string but print string without spaces?
guyz plzz somebody help me to find the sqare of first n natural no……. 🙂 ::
Hello, Your question is not clear. Is it square of sum of first n natural nos.? Please provide your question with the help of an example. Thanks
thanks very interesting keep up the amazing work thank you here is a superb weblog
I want a program for finding maximum length in my given string.. Guys help me with that ..
If my input is ant leaves elephant
I need to get the output as elephant