Sunday, July 12, 2015

Finding the length of the word in C++ using Pointers

This simple program will count the number of characters in a given string or word by the user in C++ using Pointers as our data structure.

Feel free to use my code in your programming projects at school or work.  If you have some questions please send me an email at jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

People here in the Philippines can reach me at my mobile number 09173084360.

Thank you very much and Happy Programming.



Program Listing

#include <iostream>

using namespace std;

int str_length(char *s) {
   int a=0;
   while(*s) {
       s++;
       a++;
   }
   return a;
}

main() {
    char name[100];
    cout << "Enter a Word : ";
    gets(name);
    cout << "\n\n";
    cout << "The lenght of the word is "
         << str_length(name) << ".";
    cout << "\n\n";
    system("pause");
}



No comments:

Post a Comment