Thread: about reading character from a file

  1. #1
    Registered User
    Join Date
    Apr 2002

    about reading character from a file

    Hi everyone,

    I set up two little functions that do enscryption and I want to incorporate those two functions into commandLine argument of the form <prog> file1.txt > file2.txt .
    each one of the two functions gets 4 letter words and return 4 letter word, since the only way that I know is to read characters from a file is one character at time. can anyone suggest a way that I can pass these two functions 4 letter at a time or any other way that I can adapt these two functions.

    the two functions look like this;

    /* the loop is from the main function */
    while(file.get(fp) == NULL)
    p-box( *first_msg, * return_message); /* function 1 * /

    s-box( *return_message, *another_ return_message); /* function2

    print here (another_returm_message)

  2. #2
    Registered User sean345's Avatar
    Join Date
    Mar 2002
    If you would like to read a certain number of charectors or an entire line you can use fgets.
    char String[256];
    FILE *input = fopen(FileName, "r");
    fgets(String, 256, input);
    This will get at most 256 charectors from input and store the char array to String. If fgets incounters a new line ('\n') it stops and stores what it has taken to String. If you want to only get 4 char then just change 256 to 4.

    - Sean
    If cities were built like software is built, the first woodpecker to come along would level civilization.
    Black Frog Studios

  3. #3
    Me want cookie! Monster's Avatar
    Join Date
    Dec 2001
    Manual page: fgets

  4. #4
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    If you're doing encryption, you'll probably be doing decrpytion in the same prog, and for that I expect you'll need to read in binary mode (depending on how you've encrypted the data). For that you'll need fread() and fwrite().

    while(file.get(fp) == NULL)
    this is C++, not C. If you're coding C++, best post you're code questions in the C++ forum
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 7
    Last Post: 02-02-2009, 07:27 AM
  2. Basic text file encoder
    By Abda92 in forum C Programming
    Replies: 15
    Last Post: 05-22-2007, 01:19 PM
  3. Encryption program
    By zeiffelz in forum C Programming
    Replies: 1
    Last Post: 06-15-2005, 03:39 AM
    By Registered in forum C++ Programming
    Replies: 1
    Last Post: 07-15-2002, 03:23 PM
  5. System
    By drdroid in forum C++ Programming
    Replies: 3
    Last Post: 06-28-2002, 10:12 PM