----------------解决方案--------------------------------------------------------
我也想问这个问题呢
----------------解决方案--------------------------------------------------------
请问文件内容是如何组织的呢?
----------------解决方案--------------------------------------------------------
version hear
sex F
........
frame 1 {
x1 x2 x3 x4 x5 x6
y1 1 2 6 7 9 10
y2 3 7 9 5 6 1
......
frame 2 {
.......
frame 3 {
........
----------------解决方案--------------------------------------------------------
/*此程序只是把文件里面的数字矩阵输出*/
/**********************************/
/*
version hear
sex F
frame 1 {
x1 x2 x3 x4 x5 x6
y1 1 2 6 7 9 10
frame 2 {
x1 x2 x3 x4 x5 x6
y1 2 3 4 5 6 14
y2 3 7 9 5 6 1
frame 3 {
x1 x2 x3 x4 x5 x6
y1 2 2 6 7 9 10
y2 3 7 9 5 6 1
y3 3 7 9 5 6 1
frame 4 {
x1 x2 x3 x4 x5 x6
y1 7 3 4 5 6 14
y2 8 7 9 5 6 1
y3 4 7 9 5 6 1
y4 5 7 9 5 6 1
*/
/*************************************************/
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<string.h>
int isStart(char *str)//判断不是矩阵开始,即含有字符'{'行
{
int i=0;
while(i<(int)strlen(str))
{
if(str[i]=='{')
return 0;
i++;
}
return -1;
}
int main ()
{
char str[512];
char buf[64];
char *p,*s;
FILE *fp;
int flag;
memset(str,0,sizeof(str));
memset(buf,0,sizeof(buf));
fp=fopen("1.txt","r");
s=fgets(str,512,fp);//读取一行
while(s!=NULL)
{
if(isStart(str)==0)//找到矩阵开始行
{
printf("%s:\n",strtok(str,"{"));//输出数组名
s=fgets(str,512,fp);
while(s!=NULL)//解析矩阵
{
memset(str,0,sizeof(buf));
s=fgets(str,512,fp);
if(isStart(str)==0)
{
flag=1;
break;
}
flag=0;
if(strlen(str)<2)//没有内容的行跳过
continue;
p=strtok(str," ");
p=strtok(NULL," ");
while(p)//解析每行信息,即解析出该行每一个整数
{
memset(buf,0,sizeof(buf));
strcpy(buf,p);
printf("%-4d",atoi(buf));
p=strtok(NULL," ");
}
printf("\n");
}
if(flag==1)
continue;
}
memset(str,0,sizeof(str));
s=fgets(str,512,fp);
}
getch();
return 0;
}
[此贴子已经被作者于2007-9-14 17:42:17编辑过]
----------------解决方案--------------------------------------------------------