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!
Printable View
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!
Quote:
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
}
}
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?
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".
Hello mega,
what do you mean by "export to STDOUT and use it later".Explain it clearly.
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?