How i can read a long integer from standar input and a string with as many characters as specified..

how i can read a long integer from standar input and a string with as many characters as specified in the number?

i thing that i must use the read command ofcourse....

#include <stdlib.h>
#include <stdio.h>

int main( int argc, char **argv )
{
    int    num;
    char    format[ 8 ];
    char    inps[ 100 ];

    scanf( "%d ", &num );
    sprintf( format, "%%%ds", num );
    scanf( format, inps );
    printf( "format: '%s' -- num: %d, text: %s\n", format, num, inps );
    return( 0 );
}

thnx you...

but i want to achieve this with the read command and in combination with malloc... is that possible?

What is the malloc supposed to be used for? Why so specific, is this an assignment?

I suppose that it might be possible but it would make more sense to use something like getchar() and have a loop like so:

while ( ( c = getchar() ) != EOF )
{
...
}

or use gets();

I am not sure of your reasons but it doesn't seem practical to use read() to read from stdin, unless I am missing something obvious.

Julian

its not an assignment, its for an exercise....but i dont know how to do it with read
its something like this. read (STDIN, BUFFER, SIZE)

but the i dont know how to continue, ok

printf("GIVE NUMBER");
i = read (STDIN, BUFFER, SIZE);

with pointers after or whatever...

something like this....

Let me be perfectly clear.

People who post homework and repeatedly break the homework posting rules will be banned.

Cheaters are not welcome here.

If you post homework, and do not complete the homework template completely and accurately, you will be banned.

Moderators, please enforce this important forum rule. Thank you.