I have to write console program where it changes any text to ASCII. The text has to be written to array and then converted.
For example:
input: Nc
output: 7899
I only have this, but it's converting only first char and after putting Nc there's only 78. Please help.
int main()
{
unsignedchar text;
int array[256];
int i = 0;
int ascii;
cout << "Write text:" << endl;
cin >> text;
for (int i = 0; i < 256; i++)
{
array[i] = text % 256;
text = text / 256;
}
for (i = 0; i < 256; i++)
{
ascii = (int)array[i];
}
cout << "ASCII: \n" << ascii;
system("pause");
return 0;
}
Try it out with different sizes. Try 256. If you look up 'arrays' in the tutorial you'll see how they work and why 100 would cover most sentence inputs. Try 2 and there won't be enough storage space for sentences of more than 2+1 characters and the program will crash.
strlen() is a function that is included in string.h and it determines the number of characters in the sentence. Have a look in the reference section of this site http://www.cplusplus.com/reference/cstring/strlen/?kw=strlen
You're on the right track if you study/understand/learn about each line of the code I wrote and compare/adapt it with yours. The temptation is to just copy it and not learn anything.