What's Here?
- Members: 148,794
- Replies: 504,906
- Topics: 79,515
- Snippets: 2,661
- Tutorials: 705
- Total Online: 2,171
- Members: 79
- Guests: 2,092
|
This simple little snippet will tell you the length of a string array. It might be useful to someone. But it was a simple exercise for me as I learn C++
|
Submitted By: enj316
|
|
Rating:

|
|
Views: 13,601 |
Language: C++
|
|
Last Modified: June 16, 2006 |
Instructions: This pretty simple, where message and message2 are in the main function you can enter a string and the function StringLength will tell you how many characters are in the string.
You can create many varitions with this snippet. |
Snippet
#include <iostream>
using namespace std;
int StringLength(char inputString[])
{
int length = 0;
for (int i = 0; inputString[i]!= '\0'; i++)
length++;
return length;
}
int main()
{
char message[] = "C++ Program";
char message2[] = "Wow this is great.";
cout << "The length of message is " << StringLength(message) <<endl <<endl;
cout << "The length of message2 is " << StringLength(message2) <<endl <<endl;
system("pause");
return(0);
}
Copy & Paste
|
|
|
Be Social
Reference Sheets
Bye Bye Ads
Monthly Drawing
Top Contributors
Top 10 Kudos This Month
|