Thread: redirect output

  1. #1
    Registered User
    Join Date
    Feb 2010
    Posts
    5

    redirect output

    Hello all!

    I am stuck at something i thought would be easy... Ok, this is what I'm trying to do:

    I have a (char *) array with 4 columns and 20 rows, and I want to export it to stdout.

    How do I do that?

    thanks for reading the post!

  2. #2
    Registered User
    Join Date
    Feb 2010
    Posts
    4

    use this following code.
    Code:
     
    
    #include<stdio.h>
    #include<malloc.h>
    main()
    {
            char *ptr[20]; // (char *) array with 4 columns and 20 rows, and I want to export it to stdout.  
             int  i ;
            for ( i =0; i<20; i++ )  // Allocating memory
            {
                    ptr[i]= (char *) malloc (4*sizeof ( char) );
                    scanf ( "%s",ptr[i] );
            }
            for ( i=0; i< 20 ; i++ )
            {
                    printf ( "%s\n",ptr[i] ) ; // displaying the content
            }
    
    }
    Last edited by pavun_cool; 02-26-2010 at 03:07 AM. Reason: adding new line

  3. #3
    Registered User
    Join Date
    Feb 2010
    Posts
    5
    thanks pavun_cool, that code actually works, but I need to export the table to stdout, specifically to stdout, to handle it later.... does that make any sense? Or am I missing something here?

  4. #4
    Registered User
    Join Date
    Oct 2006
    Location
    Canada
    Posts
    1,243
    I dont get it. You say you want to "export to stdout", what does that mean? STDOUT is simply a "FILE*". When you use "printf", it writes to STDOUT. There isnt anything special to do, just write stuff with printf.

    If you want to do binary output, like printing the actual array, you can use "fwrite" on the global file stream "stdout".

  5. #5
    Registered User
    Join Date
    Nov 2008
    Location
    INDIA
    Posts
    64

    Question

    Hello mega,
    what do you mean by "export to STDOUT and use it later".Explain it clearly.

  6. #6
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    STDOUT is one of the streams that is opened, and by default, connected to the monitor, when your program begins.

    If you want to "use it later", then let's talk about a file stream being opened, and moving the data to the file.

    Because anything you write to the monitor, will not be available, later on.

    Is the table you want to move and save, text data?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help for my output array
    By qwertysingh in forum C Programming
    Replies: 1
    Last Post: 02-17-2009, 03:08 PM
  2. execl()/fork() output
    By tadams in forum C Programming
    Replies: 19
    Last Post: 02-04-2009, 03:29 PM
  3. redirect console output to a String?
    By TwistedMetal in forum C Programming
    Replies: 10
    Last Post: 02-26-2008, 02:54 PM
  4. Trying to store system(command) Output
    By punxworm in forum C++ Programming
    Replies: 5
    Last Post: 04-20-2005, 06:46 PM
  5. how to redirect the output of a program?
    By dkt in forum C Programming
    Replies: 2
    Last Post: 04-25-2002, 12:05 AM