1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
|
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv){
int lines=0, rows=0, j, k;
char ch, array[1000][1000];
FILE *fin;
if(argc!=2){
exit(2);
}
fin=fopen(argv[1],"r");
if(fin==NULL) {
exit(2);
}
while(!feof(fin)){
ch=fgetc(fin);
if(ch=='\n') lines++;
}
fclose(fin);
fin=fopen(argv[1],"r");
while(!feof(fin)){
ch=fgetc(fin);
if(ch=='+' ||ch=='-'|| ch=='.'||ch=='X') rows++;
if(ch=='\n') break;
}
printf("%d %d\n", lines, rows);
fclose(fin);
fin=fopen(argv[1],"r");
while(!feof(fin)) {
for(j=0; j<lines; j++){
for(k=0; k<rows; k++){
fscanf(fin, "%c", &array[j][k]);
}
}
//printf("%d %d", lines, rows);
int i;
for(i=0; i<lines; i++){
for(j=0; j<rows; j++){
printf("%c", array[i][j]);
//printf("%d %d\n", i, j);
}}
fclose(fin);
return 0;
}
}
|