program that converts string to integer in c

May 23, 2011 at 13:12:10
Specs: Windows 7
write a program which accepts a string from the user, and replaces all occurrences of alphabets by their numeric key equivalent.
A run of the required program will look like this
Enter a string: 1 800 TAXICAB
1 800 8294222

See More: program that converts string to integer in c

Report •


#1
May 23, 2011 at 16:23:58
string to integer in c
Strange request, but whatever:
#include <iostream>
#include <string>
int main() {
  std::string str = "1 800 TAXICAB";
  unsigned num = 0;
  for (std::string::iterator it = str.begin(); it < str.end(); ++it)
    num += *it;
  std::cout << num << '\n';
  return 0;
}

EDIT: Silly me; you asked for C, not C++. Oh well.

How To Ask Questions The Smart Way


Report •

#2
May 27, 2011 at 07:49:03
Thanks anyways.... U tried atleast.........

Report •
Related Solutions


Ask Question