I want to ask for word from the user and then convert the word from string to char using 'strcpy'. Then I want to determine the sum of the ascii codes for all of the letters in the word.
However, I am having difficulties. I don't understand exactly how I can do that. This is what I have been able to do so far.
#include <iostream> #include <time.h> #include <stdlib.h> #include <string.h> using namespace std; int main() { string word; cout << "Enter word: "; getline(cin, word); /* char w[word]; strcpy(w,word.c_str()); int ('A'); cout<<char(65); */ return 0; } The commented part is where I have been trying to do the converting. I copied the code from a worksheet. Even if it did work, I don't know how, and what it all means.
Thanks for your help.
string.hin a C++ program, you need to find a better class.strcpyis pure stupidity. There's simply no need to make a copy, and even if there was, you can copy strings directly.