Code:
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#define MAX_LEN 40
int main() {
int pos;
char *line, *aster, *blank;
line=malloc( MAX_LEN+1 );
aster=malloc( 2 );
blank=malloc( MAX_LEN+1 ); // you're copying to this - better have space
strcpy( line, " " ); // 40 spaces
strcpy( aster, "*" );
strcpy( blank, "" );
printf( "enter star position (1-40):" );
scanf( "%d",&pos );
if(pos>0 && pos<41) {
printf( "\n" );
printf( " 1 2 3 4\n" );
printf( "1234567890123456789012345678901234567890\n" );
puts( strcat( strncat( blank,line,pos-1 ),aster ) );
} else
printf( "out of range" );
return 0;
}