Geeks Talk

Prepare for your Next Interview


Welcome to the Geeks Talk forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact us.

array of string operation

This is a discussion on array of string operation within the C and C++ forums, part of the Software Development category; how do we find the string length without using strlen() function?...

Go Back   Geeks Talk > Software Development > C and C++
Register Blogs FAQ Tag Cloud Calendar Mark Forums Read
  #1 (permalink)  
Old 06-05-2007
Junior Member
 
Join Date: Jun 2007
Location: bangalore
Posts: 3
Thanks: 1
Thanked 3 Times in 1 Post
shivaram.cunchala is on a distinguished road
array of string operation

how do we find the string length without using strlen() function?
Reply With Quote
The Following 3 Users Say Thank You to shivaram.cunchala For This Useful Post:
Sponsored Links
  #2 (permalink)  
Old 06-05-2007
Expert Member
 
Join Date: Sep 2006
Location: Bengalooru (Formerly called Bangalore), India
Posts: 486
Thanks: 2
Thanked 29 Times in 28 Posts
kalayama is on a distinguished road
Re: array of string operation

There are many ways of doing it. Just running through the characters of the string inside a for/while loop will do the trick.

Cheers!
Kalayama
__________________
[COLOR="Blue"][SIZE="2"]"If you are not living on the edge of your life, you are wasting space"[/SIZE][/COLOR]

Someone says "Impossible is nothing". The man next him says "Let me see you licking your elbow tip!"
Reply With Quote
The Following User Says Thank You to kalayama For This Useful Post:
  #3 (permalink)  
Old 08-13-2007
Junior Member
 
Join Date: Aug 2007
Location: bangalore
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
sagar123 is on a distinguished road
Re: array of string operation

char ch[20];
int i=0,len=0
//enter string and store it a array;

while(ch[i]!='\0')
{ len=len+1;
i++;
}
cout<<"length is" <<len;
Reply With Quote
  #4 (permalink)  
Old 10-27-2007
Contributing Member
 
Join Date: Jul 2007
Location: India TamilNadu, Udumalpet
Posts: 39
Thanks: 19
Thanked 6 Times in 6 Posts
kaliswaranbsc is on a distinguished road
Re: array of string operation

#include<stdio.h>
#include<conio.h?
void main()
{
char ch[20];//to store string into the arry
int i=0,length=0
while(ch[i]!='\0')// while arry not equal to null. String stores at the end as null
{
length+=1;//length=length+1
i++;
}
printf("The String length is",length);
}
Reply With Quote
  #5 (permalink)  
Old 11-21-2007
Junior Member
 
Join Date: Nov 2007
Location: bangalore
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
chakri32007 is on a distinguished road
Re: array of string operation

Quote:
Originally Posted by sagar123 View Post
char ch[20];
int i=0,len=0
//enter string and store it a array;

while(ch[i]!='\0')
{ len=len+1;
i++;
}
cout<<"length is" <<len;
could you please tell , what for len is used ............ without len we can get the ans
Reply With Quote
  #6 (permalink)  
Old 11-22-2007
Contributing Member
 
Join Date: Jul 2007
Location: India TamilNadu, Udumalpet
Posts: 39
Thanks: 19
Thanked 6 Times in 6 Posts
kaliswaranbsc is on a distinguished road
Re: array of string operation

len is used for find the length of the string
Reply With Quote
  #7 (permalink)  
Old 11-22-2007
Junior Member
 
Join Date: Nov 2007
Location: India
Posts: 7
Thanks: 0
Thanked 1 Time in 1 Post
dgopinath_1974 is on a distinguished road
Re: array of string operation

char *ch;
gets(ch);
for(int i=0;ch[i]!='\0';i++);
printf("%d",i);
Reply With Quote
  #8 (permalink)  
Old 11-28-2007
Junior Member
 
Join Date: Nov 2007
Location: Bangalore
Posts: 2
Thanks: 0
Thanked 2 Times in 1 Post
msubbums is on a distinguished road
Re: array of string operation

To find length of an array use this

int a;

a=printf("12345");

/* a has length of string "12345" i.e 5
Reply With Quote
The Following 2 Users Say Thank You to msubbums For This Useful Post:
  #9 (permalink)  
Old 11-29-2007
Junior Member
 
Join Date: Nov 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
sonal_seema is on a distinguished road
Re: array of string operation

[QUOTE=shivaram.cunchala;12881]how do we find the string length without using strlen() function?[/QUOTby counting the number of character with spaces
Reply With Quote
Reply

  Geeks Talk > Software Development > C and C++

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads

Thread Thread Starter Forum Replies Last Post
Difference between String.Convert Vs String.ToString jbanx C# 6 03-24-2008 01:02 PM
Active Screen Operation Geek_Guest QTP 1 12-27-2007 09:01 AM
display string without having underscore if we send string with underscore ausprem2000 Oracle 1 05-28-2007 07:46 AM
Object operation failed Geek_Guest Rational Robot 0 04-16-2007 09:05 AM
How to make sure that the operation on database is successful? sivaprasademani SQL Server 2 04-04-2007 02:03 AM


All times are GMT -4. The time now is 02:06 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.3.1
Copyright © 2009 GeekInterview.com. All Rights Reserved