这样子不?- #include <stdio.h>
- #include <stdlib.h>
- #include <conio.h>
- #include <windows.h>
- #include <string.h>
- #include <graphics.h>
- #include <easyx.h>
- int main()
- {
- int s=1,m=1,n=0,n1=0,n2=0;
- char ch;
-
- #define THECHSIZE 128
- char *ch2=(char *)malloc(THECHSIZE*THECHSIZE*sizeof(char));//分配空间存储每一行,最大为 THECHSIZE 行,每行 THECHSIZE 个字符
- if(!ch2)return 1;
- char *pp1=ch2,*pp2=ch2;
- size_t nnn;
-
- FILE *file = fopen("1.txt", "r");
- while ((ch = fgetc(file)) != EOF)
- {
- n=n+1;
- if (ch == '[') {
- sprintf(pp1,"%d,%d,%d,",s,m, n);
- nnn=strlen(pp1);
- printf("%d,%d,%d,",s,m, n);
- n1=n;
- }
- if (ch == ']') {
- pp1+=nnn;
- sprintf(pp1,"%d\n",n);
- pp2+=THECHSIZE;
- pp1=pp2;
- printf("%d\n", n);
- s=s+1;
- n2=n;
- }
- if (ch == '\n'){
- m=m+1;
- n = 0;
- }
-
- }
-
- s-=1;
- fclose(file);
-
- printf("\n请输入行n的值(1-%d):",s>THECHSIZE?THECHSIZE:s);
- scanf("%d",&n);
- if((n<=0) || (n>THECHSIZE) || (n>s)){
- printf("\n输入错误\n");
- }else{
- printf("\n第%d行的值为:\n%s\n",n,ch2+(n-1)*THECHSIZE);
- }
-
- free(ch2);
- return 0;
- }
复制代码
|