|
| » 首页 » 电脑_数码 » 编程 » 这是一个矩阵,为什么会多输出呢. |
这是一个矩阵,为什么会多输出呢. |
|
#include <iomanip> #include<fstream> #include<string> #include<stdio.h> using namespace std; const int maxsize=100; const int maxrow=10; const int OK=1; const int ERROR=0; typedef struct { int i, j; int e; }Ttrible; typedef struct { int mu,nu,tu; Ttrible data[maxsize+1]; int rpos[maxrow+1]; }TSMatrix; /*创建一个新稀疏矩阵*/ int main() { TSMatrix T; FILE *fp; int i=1,j=1; int k=0; int m=1; char str[20]; int t; char ch; fp=fopen("sparsematrix.txt","r"); while((ch=fgetc(fp))!=EOF) { if((ch!='\n')&&(ch!=' ')) { str[k++]=ch; }//写入字符串 else { str[k]='{ask}'; k=0; t=atoi(str); T.data[m].e=t; T.data[m].i=i; T.data[m].j=j; if(ch==' ') { j++; } else if(ch=='\n') { i++; j=1; } cout<<T.data[m].e<<T.data[m].i<<T.data[m].j<<endl;///*/ } /*如果不为0先处理 字符串清空*/ for(m=1;m<maxsize+1;m++) { if(T.data[m].e!=0) { //cout<<T.data[m].e<<T.data[m].i<<T.data[m].j<<endl; } } } return OK; } 这个程序在遇到空格和换行时就会输出两次是为什么呢? 0 0 0 1 0 0 0 0 0 0 0 2 0 0 |
![]() |
|
|
最后一个0的后面还有个空格,然后才回车的! 最后一个0的后面还有个空格,然后才回车的! 卖糕的,俺不懂 |
| 《这是一个矩阵,为什么会多输出呢.》答案收集时间:2008-06-14 14:32:45 |