C で CGI

  まずは Content-type



拡張子Content-type
txttext/plain
htm htmltext/html
jpg jpegimage/jpeg
gifimage/gif
bmpimage/bmp
zipapplication/x-zip-compressed
docapplication/msword
xlsapplication/vnd.ms-excel
pptapplication/vnd.ms-powerpoint
exe dllapplication/vnd.ms-download
eml mht mhtml nwsmessage/rfc822
fdfapplication/vnd.fdf
pdfapplication/pdf
rmiaudio/mid
qt movvideo/quicktime
avivideo/x-msvideo
tiffimage/tiff
wav mp1 mp2 mp3audio/wav
alsAudio/X-Alpha5
以外application/octet-stream



  引き数の表示



  
#include <stdio.h>

void
main( int argc, char *argv[] )
{

	int i;

	printf( "Content-Type: text/html; Charset=shift_jis\n\n" );

	printf( "<HTML>\n" );
	printf( "<HEAD><TITLE>\n" );
	printf( "%s\n", argv[0] );
	printf( "</TITLE></HEAD>\n" );
	printf( "<BODY>\n" );

	printf( "<TABLE >\n" );
	for( i = 1; i < argc; i++ ) {
		printf( "<TR>\n" );

		printf( "<td>%s</td>\n", argv[i] ); 

		printf( "</TR>\n" );
	}
	printf( "</TABLE>\n" );

	printf( "</BODY>\n" );
	printf( "</HTML>\n" );


}
  



  引き数の表示(2) printf --> fprintf

  
#include <stdio.h>

void
main( int argc, char *argv[] )
{

	int i;

	fprintf( stdout, "Content-Type: text/html; Charset=shift_jis\n\n" );

	fprintf( stdout, "<HTML>\n" );
	fprintf( stdout, "<HEAD><TITLE>\n" );
	fprintf( stdout, "%s\n", argv[0] );
	fprintf( stdout, "</TITLE></HEAD>\n" );
	fprintf( stdout, "<BODY>\n" );

	fprintf( stdout, "<TABLE >\n" );
	for( i = 1; i < argc; i++ ) {
		fprintf( stdout, "<TR>\n" );

		fprintf( stdout, "<td>%s</td>\n", argv[i] ); 

		fprintf( stdout, "</TR>\n" );
	}
	fprintf( stdout, "</TABLE>\n" );

	fprintf( stdout, "</BODY>\n" );
	fprintf( stdout, "</HTML>\n" );

}
  



  画像の表示

  
#include <stdio.h>
#include <fcntl.h>

void
main( int argc, char *argv[] )
{
	int gif;
	int size = 6837;
	int i;

	char buff[1024];

	fprintf( stdout, "Content-type: image/gif\n" );
	fprintf( stdout, "Content-length: 6837\n\n" );

	gif = open( "d:\\kadai\\doumi\\yahoo.gif", O_RDONLY | O_BINARY );

	setmode( fileno(stdout), O_BINARY );

	while( 1 ) {

		i = read( gif, buff, 1000 );
		if ( i <= 0 ) {
			break;
		}

		size = size - i;

		fwrite( buff, i, 1, stdout );

		if ( size <= 0 ) {
			break;
		}

	}

	close( gif );

}
  










  infoboard   管理者用   





フリーフォントWEBサービス
SQLの窓WEBサービス

SQLの窓フリーソフト

素材

一般WEBツールリンク

SQLの窓

フリーソフト

JSライブラリ