?? readmatrix.c
字號:
/*read a matrix from a file*/#include "stdio.h"#include "stdlib.h"#define CHARSIZE sizeof(char)#define INTSIZE sizeof(int)int main(){ char *filename; FILE *fd; /*file pointee to the file */ int i,j; int row,column; int value; filename=(char *)malloc(CHARSIZE*128);if (filename==NULL){printf("CANNOT allocate space for filename\n");exit(0);} printf("Read the content of a file\n"); printf("Filename:"); scanf("%s",filename); fd=fopen(filename,"r"); /*open a file for read only and the stream is positioned at the beginning ofthe file*/if(fd==NULL) /*error in opening the file*/ {free(filename);printf("CANNOT open the file %s coorectly\n",filename);exit(0); /*exit the system*/ }/*if*/fread(&row,INTSIZE,1,fd);fread(&column,INTSIZE,1,fd);printf("Row=%d,Column=%d\n",row,column);for (i=0;i<row;i++) { for(j=0;j<column;j++) { fread(&value,INTSIZE,1,fd); printf("%d ",value); }/*for j*/ printf("\n");}/*for i*/fclose(fd);/*close file pointer*/free(filename);/*free dynamic allocated space*/return(0); }/*main*/
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -