Thread: Char

  1. #16
    Registered User
    Join Date
    Mar 2005
    Posts
    7
    Try working off of something like this...
    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");
    }
    This should be somewhat close to what you're looking for... give it a go, change a few things... but it's a start.

    Edit: Here it is... sort of.
    Last edited by anthrax759; 03-21-2005 at 07:15 PM.

  2. #17
    Registered User
    Join Date
    Jan 2005
    Posts
    30
    Code:
    #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;
    }
    it says "invalid conversion from void to char" when i try to compile it
    ADRUMSOLO4U

  3. #18
    Slave MadCow257's Avatar
    Join Date
    Jan 2005
    Posts
    735
    watch the parameters you give it,
    from
    http://msdn.microsoft.com/library/de...eamgetline.asp
    basic_istream& getline(
    char_type *_Str,
    streamsize _Count
    BTW
    the large number of ifs would be well suited for a switch statement

    EDIT
    2 more things...
    for(A=0; A>50; A++)
    Did you mean A<=50?
    if(sentence[A]=32){
    That is assignment, you want comparison
    if(sentence[A]==32)
    Last edited by MadCow257; 03-21-2005 at 07:22 PM.

  4. #19
    Registered User
    Join Date
    Jan 2005
    Posts
    30
    im not that far yet in my studies to know how to use a switch statement
    im just using online tutorials to learn
    ADRUMSOLO4U

  5. #20
    Registered User mrafcho001's Avatar
    Join Date
    Jan 2005
    Posts
    483
    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;}

  6. #21
    Registered User
    Join Date
    Jul 2003
    Posts
    26
    As a side note, strings use the format

    Code:
    getline(cin, blah, '\n');
    rather than

    Code:
    cin.getline(blah, '\n');
    --LiKWiD
    Becoming un-noobified one day at a time.

  7. #22
    Registered User
    Join Date
    Jan 2005
    Posts
    30
    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
    ADRUMSOLO4U

  8. #23
    Registered User mrafcho001's Avatar
    Join Date
    Jan 2005
    Posts
    483
    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..

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C++ ini file reader problems
    By guitarist809 in forum C++ Programming
    Replies: 7
    Last Post: 09-04-2008, 06:02 AM
  2. Sorting Linked Lists
    By DKING89 in forum C Programming
    Replies: 6
    Last Post: 04-09-2008, 07:36 AM
  3. code condensing
    By bcianfrocca in forum C++ Programming
    Replies: 4
    Last Post: 09-07-2005, 09:22 AM
  4. Passing structures... I can't get it right.
    By j0hnb in forum C Programming
    Replies: 6
    Last Post: 01-26-2003, 11:55 AM
  5. String sorthing, file opening and saving.
    By j0hnb in forum C Programming
    Replies: 9
    Last Post: 01-23-2003, 01:18 AM