Week12
#include <stdio.h>
int main()
{
///檔案指標 fout = 開檔案("檔名", "用什麼模式")
FILE * fout = fopen("file.txt", "w");/// w = write
printf("Hello World");
fprintf(fout, "Hello World在檔案裡\n");
}
build and run 後就會在目錄出現這個txt檔
#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);
}
#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);}
| ///在project-properties 到build target 可以去上面把目錄改成小數點. ///build target debug 和 release 都要改成小數點. ///記得去freeglut把freeglut.dll放到錄中 #include <stdio.h> | |
| #include <GL/glut.h> | |
| float teapotX=0 , teapotY=0; | |
| void display() | |
| { | |
| glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); | |
| glPushMatrix(); | |
| glTranslatef(teapotX,teapotY,0); | |
| glutSolidTeapot(0.3); | |
| glPopMatrix(); | |
| glutSwapBuffers(); | |
| } | |
| void mouse(int button,int state,int x,int y) | |
| { | |
| if(state==GLUT_DOWN) | |
| { | |
| teapotX = (x-150)/150.0; | |
| teapotY = (150-y)/150.0; | |
| } | |
| display(); | |
| } | |
| int main(int argc,char** argv) | |
| { | |
| glutInit(&argc,argv); | |
| glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH); | |
| glutCreateWindow("week12"); | |
| glutDisplayFunc(display); | |
| glutMouseFunc(mouse); | |
| glutMainLoop(); | |
| } |




沒有留言:
張貼留言