hey, ummm, i wanna know what happens, when a character is entered.....does it turn into a number?? what?? ha, idk, im confused, plz help me
Printable View
hey, ummm, i wanna know what happens, when a character is entered.....does it turn into a number?? what?? ha, idk, im confused, plz help me
or just sit there, and wonder at my stupidity
Well, I'm not sure that your question was worded extremely well, but of course a character doesn't become an integer just because.
well...hmmm....lets say you enter the letter "a"....what is that to the computer? does it equal "a"?
It stays a character untill you cast it or make it into something else
Code:
char character = 'L'
cout << int(character) << endl;
// this will display the character, in this case 'L' as a number
// if you wanna know what happens try it yourself!
EDIT:
knowing this will display the ASCII character for 'L' you can make a program that will display the ASCII number for every character from ASCII and also the ones that you have to press 'alt' + [numbers on the number pad] and makes weird characters... so then youll know what combination makes what character.
I had a program like that one time..
yea, you see, what im doing is, im trying to make an encrypter, to code a sentence...and also the vice-varsa to decrypt it, of course
im also gonna need to know what a space comes out to be....so that when it is encryted the program doesnt go crazy
build the program i told, the one that displays all the numbers from 0 - 255 into ASCII characters.. those are all the ASCII characters. and then youll know what is what..
That will help you
If you want to simply make it unreadable by your friends, output the characters to your file as mrafcho001 said, then create a program to 'decode' the same. I believe you can find what a space is by replacing 'L' with ' '.
EDIT: As he said. :)
that is what im trying to do...well, part of it anyway....it keeps saying sentence cannot be used as a function...but im not trying to...Code:int main(){
cout<<"Please Enter a sentence no longer than 50 letters, and use only lower-case letters, please:/n";
char sentence(51);
int A;
for(A=0; A>50; A++){
if(sentence(A)=97){
sentence(A)=01;
}
}
}
btw, 97 is the lower-case ansi version of "a"
sentence(A) is trying to call sentence() as a function. You want to use it as an array, so you'd useCode:sentence[A]
oh crap, lol, i forgot about that!!! woa....im realy out of it today
Don't worry 'bout it... happens to the best of us... ;) Also, you're not setting anything to your array 'sentence'... regardless of what they enter, without something to catch the input, you'll get nothing back... don't forget good ol' cin function.
oh yea.....should i use cin for characters though? i dont want numbers
man, im such a noob at this, lol
Remeber if they enter a space in the sentece the string will only remember everything before the first space... so use
just a noteCode:char blah[51];
cout << "input sentece: ";
cin.getline(cin, blah);
EDIT:
BTW you should use strings:
Code:
#include <string>
// blah blah
string sentence;
cout << "input sentece: ";
cin.getline(cin, sentence);
//this will input everything in the string including the spaces..
//O wait.. i am not sure you can access every character in the string separately.. so you might wann stick with arrays..
//God what a pointless 'EDIT:' :)
wow, that helped alot, i almost threw my compter out the window, because i was using just cin.....and it didnt work
Try working off of something like this...
This should be somewhat close to what you're looking for... give it a go, change a few things... but it's a start.Code:cout << "Enter the sentence you wish to have encrypted." << endl;
char x[256];
char str[51];
cin >> x;
cout << endl;
if(strlen(x)>50){
for(int i = 0; i < 50;i++)
{
str[i] = x[i];
}
} else {
for(int j = 0; j < strlen(x);j++)
{
str[j] = x[j];
}
}
cout << int(&str) << endl;
system("pause");
}
Edit: Here it is... sort of.
it says "invalid conversion from void to char" when i try to compile itCode:#include <stdio.h>
#include <windows.h>
#include <iostream>
using namespace std;
int main(){
cout<<"Please Enter a sentence no longer than 50 letters,\n and use only lower-case letters, please:\n";
char sentence[51];
cin.getline(cin, sentence[51]);
int A;
for(A=0; A>50; A++){
if(sentence[A]=32){sentence[A]=0;}
if(sentence[A]=97){sentence[A]=01;}
if(sentence[A]=98){sentence[A]=02;}
if(sentence[A]=99){sentence[A]=03;}
if(sentence[A]=100){sentence[A]=04;}
if(sentence[A]=101){sentence[A]=05;}
if(sentence[A]=102){sentence[A]=06;}
if(sentence[A]=103){sentence[A]=07;}
if(sentence[A]=104){sentence[A]=27;}
if(sentence[A]=105){sentence[A]=28;}
if(sentence[A]=106){sentence[A]=10;}
if(sentence[A]=107){sentence[A]=11;}
if(sentence[A]=108){sentence[A]=12;}
if(sentence[A]=109){sentence[A]=13;}
if(sentence[A]=110){sentence[A]=14;}
if(sentence[A]=111){sentence[A]=15;}
if(sentence[A]=112){sentence[A]=16;}
if(sentence[A]=113){sentence[A]=17;}
if(sentence[A]=114){sentence[A]=18;}
if(sentence[A]=115){sentence[A]=19;}
if(sentence[A]=116){sentence[A]=20;}
if(sentence[A]=117){sentence[A]=21;}
if(sentence[A]=118){sentence[A]=22;}
if(sentence[A]=119){sentence[A]=23;}
if(sentence[A]=120){sentence[A]=24;}
if(sentence[A]=121){sentence[A]=25;}
if(sentence[A]=122){sentence[A]=26;}
cout<< sentence[A] <<flush;
}
int z;
cin>> z;
}
watch the parameters you give it,
from
http://msdn.microsoft.com/library/de...eamgetline.asp
BTWQuote:
basic_istream& getline(
char_type *_Str,
streamsize _Count
the large number of ifs would be well suited for a switch statement
EDIT
2 more things...
Did you mean A<=50?Quote:
for(A=0; A>50; A++)
That is assignment, you want comparisonQuote:
if(sentence[A]=32){
if(sentence[A]==32)
im not that far yet in my studies to know how to use a switch statement
im just using online tutorials to learn
it works if you make 'sentece' a string....
also in your code you are making a little mistake
Code:if(sentence[A]=32){sentence[A]=0;}
//should be:
if(sentece[A] == 32) { sentence[A] = 0;}
As a side note, strings use the format
rather thanCode:getline(cin, blah, '\n');
Code:cin.getline(blah, '\n');
whats funny is...that was the easy part of what i have to do...lol
now i must change the array to one long number, and then code THAT, lol
well if its a string... becoming a number... i am not sure you can do that.. you can try casting
Code:
string word = "blah blah";
cout << int(word) << endl;
// i highly doubt thats gonna work though..