Week12-1
CodeBlocks開啟,開檔案week12-1 printf_fprintf.cpp
int main()
{
FILE * fout = fopen("file.txt", "w");
printf("Hello World\n");
fprintf(fout,"Hello World檔案在這裡");
}

執行後會出現記事本
#include <stdio.h>
int main()
{
FILE * fin = fopen("file.txt", "r");
char line[100];
fscanf(fin,"%s",line);
printf("從file.txt讀到了:%s\n",line);
fscanf(fin, "%s", line);
printf("從file.txt讀到了:%s\n",line);
}

Week12-3
開檔案week12-3_many_numbers_scanf_printf_fscnaf_fprintf.cpp
#include <stdio.h>int main(){ int a[10]={10,20,30,40,50,60,70,80,90,100}; int b[10]={};
FILE*fout=fopen("file3.txt","w"); for(int i=0;i<10;i++){ printf("%d ",a[i]); fprintf(fout,"%d ",a[i]); } printf("\n"); fprintf(fout,"\n"); fclose(fout);
FILE*fin=fopen("file3.txt","r"); for(int i=0;i<10;i++){ fscanf(fin," %d",&b[i]); printf("b%d:%d ",i,b[i]); } fclose(fin);}
出現一個會跟著你滑鼠點擊移動位置的茶杯
Week12-4
開GLUT專案week12-4 week keyboard_mouse
#include <stdio.h>
#include <GL/glut.h>
float teatopX=0, teatopY=0;
void display()
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glTranslatef(teatopX,teatopY,0);
glutSolidTeapot( 0.3 );
glPopMatrix();
glutSwapBuffers();
}
void mouse(int botton,int state,int x, int y)
{
if(state==GLUT_DOWN){
teatopX = (x-150)/150.0;
teatopY = (105-y)/150.0;
}
display();
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GL_DOUBLE | GLUT_DEPTH);
glutCreateWindow("week12");
glutDisplayFunc(display);
glutMouseFunc(mouse);
glutMainLoop();
}





.png)
.png)


.png)
沒有留言:
張貼留言