Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 136,177 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 2,001 people online right now. Registration is fast and FREE... Join Now!




convert string to characters and search strings

 
Reply to this topicStart new topic

convert string to characters and search strings, search strings

wartech
5 Aug, 2007 - 06:14 PM
Post #1

D.I.C Head
Group Icon

Joined: 16 Oct, 2006
Posts: 106



Thanked: 3 times
My Contributions
Hi Everyone,
I am trying to convert a string into characters. I also need to count the number of spaces in the string. Your help is appreciated. I have only been able to count the number of characters in the string. Thanks for your help!

CODE

#include <iostream>
using std::cin;
using std::cout;
using std::endl;

int main()
{
   const int MAX = 80;                // Maximum array dimension
   char buffer[MAX];                  // Input buffer
   int count = 0;                     // Character count

   cout << "Enter a string of less than 80 characters:\n";
   cin.getline(buffer, MAX, '\n');    // Read a string until \n

   while(buffer[count] != '\0')       // Increment count as long as
      count++;                        // the current character is not null

   cout << endl;
    cout << "The string \"" << buffer "\" has " << count << " characters.";
   cout << endl;

    system("Pause");
   return 0;
}

User is online!Profile CardPM
+Quote Post

Xing
RE: Convert String To Characters And Search Strings
5 Aug, 2007 - 09:33 PM
Post #2

D.I.C Addict
Group Icon

Joined: 22 Jul, 2006
Posts: 723



Thanked: 2 times
Dream Kudos: 1575
My Contributions
Take a look at std:find algorithm.
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/2/08 12:56AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month