#include<stdio.h>//外掛printf() fprintf() fscanf() fopen()
int main(int argc,char**argv)
{
FILE * fout=NULL;//檔案指標file output變數
fout=fopen("a.txt","w+");//開啟檔案a.txt 模式write+
printf("Hello World\n");
fprintf(fout,"Hello World\n");//改裝printf變成fprintf
}
備份的程式碼 以後需要
#include <stdio.h> ///step01 外掛 printf(), fprintf(), fscanf(), fopen()
int main( int argc, char** argv )
{
/// FILE * fout=NULL;///step01 檔案指標 file output 變數
/// fout = fopen("檔名.txt", "w+");///step01 開啟檔案,檔名.txt, 模式write
///
/// printf("Hello World\n");
/// fprintf(fout, "Hello World\n");///step01 改裝 printf() 變 fprintf()
///先把舊程式 註解 掉
FILE * fin = NULL;///step03 改成讀檔
fin = fopen("檔名.txt", "r"); ///step03 開啟step01/step02的檔案,Read
///scanf( "%d", &n ); //int n
///scanf( "%c", &c ); //char c
///scanf( "%f", &f ); //float f
///scanf( "%s", line ); //char line[100];
char line[100]; ///step03 宣告一個字串 line
fscanf(fin, "%s", line); ///step03 讀入一個字串
printf("現在讀到的是 %s \n", line );///step03 順便印出字串
fscanf(fin, "%s", line); ///step03 讀入一個字串
printf("現在讀到的是 %s \n", line );///step03 順便印出字串
}
#include <stdio.h>
#include <GL/glut.h>
float angle=0, diff=2;///上週程式,會增加、會減少!!!
///float angle[20]={};//都是0的陣列 angle (下週Week16-1接著教)
//(下週Week16-1接著教) 用 fprintf() 把角度狂印, fscanf() 播動畫 frame-by-frame
void timer(int t)///上週程式,會增加、會減少!!!
{
glutTimerFunc( 30, timer, t+1 );///上週程式 設定新的timer
angle += diff;///上週程式,會增加、會減少!!!
if(angle>90) diff = -2;///上週程式,會增加、會減少!!!
if(angle<0) diff = +2;///上週程式,會增加、會減少!!!
glutPostRedisplay();///上週教display();
}
void display()
{
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glPushMatrix();///Step05-2
glutSolidTeapot( 0.3 );///身體
glPushMatrix();///Step05-2
glTranslatef(-0.3,0,0);
glRotatef(angle, 0,0,1);//(下週Week16-1接著教) angle[0]
glTranslatef(-0.3,0,0);
glutSolidTeapot( 0.3 );///左手臂, 但是,要用 T-R-T移位置
glPushMatrix();
glTranslatef(-0.3, 0,0);
glRotatef(angle, 0,0,1);//(下週Week16-1接著教) angle[1]
glTranslatef(-0.3, 0,0);
glutSolidTeapot( 0.3 );///左手肘
glPopMatrix();
glPopMatrix();///Step05-2
glPushMatrix();///Step05-2
glTranslatef(+0.3,0,0);
glRotatef(-angle, 0,0,1);//(下週Week16-1接著教) angle[2]
glTranslatef(+0.3,0,0);
glutSolidTeapot( 0.3 );///右手臂
glPushMatrix();///step05-3
glTranslatef(+0.3,0,0);
glRotatef(-angle, 0,0,1);//(下週Week16-1接著教) angle[3]...
glTranslatef(+0.3,0,0);
glutSolidTeapot( 0.3 );///右手肘
glPopMatrix();///Step05-3
glPopMatrix();///Step05-2
glPopMatrix();///Step05-2
glutSwapBuffers();
}
int main( int argc, char** argv )
{
glutInit( &argc, argv );
glutInitDisplayMode( GLUT_DOUBLE | GLUT_DEPTH );
glutCreateWindow( "week15 many angles" );
glutDisplayFunc( display );
glutTimerFunc( 0, timer, 0);
glutMainLoop();
}///先不放貼圖, 先不放打光
沒有留言:
張貼留言