Thread: How would I be able to do this?

  1. #1
    Registered User
    Join Date
    Sep 2009

    How would I be able to do this?

    HI, I am a noob, and I was just wondering if there was a way to take a text in the same directory as the project files/exe.. And print it in a console window...
    For example)
    I have a text file name text.txt
    Text.txt has the words "hello world"

    how could I make the program grab that text.txt files characters "hello world" and print it in the console window?

  2. #2
    The larch
    Join Date
    May 2006
    #include <stdio.h>
    int main(void)
        int n;
        while ((n = getchar()) != EOF) {
        return 0;
    This is how I would do it, and this is how I would run the program (on Windows):

    myprogram < Text.txt

    But I suppose you'd have to do it with file operations. You might start with I/O functions, particularly with fopen.
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  3. #3
    Or working on it anyways mramazing's Avatar
    Join Date
    Dec 2005
    Lehi, UT
    You should read the tutorial on this site for file i/o. That will have everything you need.
    -- Will you show me how to c++?

Popular pages Recent additions subscribe to a feed