Thread: Assignment to decrypt a text.

  1. #1
    False Return hubris's Avatar
    Join Date
    Apr 2009
    Posts
    33

    Assignment to decrypt a text.

    I'm approaching you guys for help because I really want to get this assignment right.

    First: My main looks like this:
    Code:
    #include <iostream>
    #include <string>
    #include <cstring>
    
    using namespace std;
    
    int main()
    {
    	ifstream inFile;
    	string fileName;
    	string message;
    	
    	
    	cout << "Please enter the file name you want to decrypt or encrypt:  " << endl;//the encryption part was a maybe extracredit so ignore.
    	cin << fileName;
    	
    	inFile.open(fileName.C_str();
    	
    
    	
    system("pause");
    }
    It's rough but it will give you an idea of what I'm doing...
    I want to create an array (c string I think?) but I've stopped at [ because I want to know for sure I was thinking of beginning a function something like...
    Code:
    char inChar(char one&, one);
    {
         while(inFile)
    	{
    		inFile >> one;
    		if(one > '\0')
                            {
    This is where I would like to send it to a reader function outside. The reader function would be the array I just mentioned to store the chars.
    My questions: how many spots I should give it and why. (Explain how the compiler "sees" characters so that I can best understand what to tell it.)
    How do I "properly" call my array from the first function to send the data. My instructor covered this in class but I didn't manage to get all the notes (she types very fast)
    last since I can't nest functions in functions, can I nest any number of different operations of diferent data types within my function or is there a limit to that. I know I can't break an if or then but are there some other conflicts I should be wary of when attempting such integration?
    Thank you in advance for any help.

  2. #2
    Registered User
    Join Date
    Mar 2008
    Posts
    71
    First of all, it's cin >> FileName. Second, you're missing a parenthesis on the next line. Third, in the inChar function, what are the arguments supposed to be? If the first one was supposed to be a reference to char, the syntax is char& one, or char &one, or char & one, but NOT char one&. And after the comma...you can't have a variable without a type, and you can't have a variable named the same as another one.

    How can an array be a function? You mean having a function that would return an array?

    How many spots? You mean how much memory should you allocate? I don't think you have to allocate any, just use <string>.

    The compiler doesn't "see" anything. The compiler "sees" a static or dynamic array, with each element containing one character, the last one being NULL.

    How do you call an array...you mean passing the array to the function or returning it? Either way it's done with a pointer or reference.

    You can stuff as much as you want in any given function, provided it doesn't violate any syntax rules.

    You should be wary of anything that violates any syntax rules.

    Cheers,

    Gabe

  3. #3
    False Return hubris's Avatar
    Join Date
    Apr 2009
    Posts
    33

    thank you

    Quote Originally Posted by G4B3 View Post
    First of all, it's cin >> FileName. Second, you're missing a parenthesis on the next line.
    I did say it was rough.

    Thank you for your help. When exploring any new discipline of thought, the first step is knowing its rules. thats why I'm here.
    Last edited by hubris; 05-26-2009 at 12:19 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 10-27-2006, 01:21 PM
  2. A bunch of Linker Errors...
    By Junior89 in forum Windows Programming
    Replies: 4
    Last Post: 01-06-2006, 02:59 PM
  3. How to use FTP?
    By maxorator in forum C++ Programming
    Replies: 8
    Last Post: 11-04-2005, 03:17 PM
  4. Removing text between /* */ in a file
    By 0rion in forum C Programming
    Replies: 2
    Last Post: 04-05-2004, 08:54 AM
  5. Ok, Structs, I need help I am not familiar with them
    By incognito in forum C++ Programming
    Replies: 7
    Last Post: 06-29-2002, 09:45 PM