邻接矩阵输出程序(问题)
2014-03-02 16:38
155 查看
#ifndef MAIN_HEAD #define MAIN_HEAD #include <vector> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <memory.h> #include <time.h> #include <math.h> #include <algorithm> #include <iostream> #define N 25 #define INF 999 using namespace std; int f_read_file1(int topo ); #endif
上面是头文件
#include "main.h"
#define TURE 1
#define FALSE 0
#define ARRIVING 1
#define LEAVING 0
#define NOEVENT -1
FILE *fp_1=fopen("test.txt","w");
int main()
{
int i,j;
int topo
;
int link_sum=0;
////读取邻接表文件到数组
if (f_read_file1(topo)==0)
{
printf("文件打开失败!\n");
return 0;
}
////显示邻接数组
printf("\n/*****************原始网络的带权临接矩阵如下:***************************/\n");
for (i=0;i<N;i++)
{
for (j=0;j<N;j++)
{
if (topo[i][j]!=INF) link_sum++;
printf("%d ",topo[i][j]);
}
printf("\n");
}
link_sum=link_sum/2;
printf("链路数总和为:%d \n",link_sum);
}
int f_read_file1(int topo
)
{
char ch_read;
int i,j;
char str[]={"0"};
char ch_qz[]={"0"},ch_qz_ini[]={""};///ch_qz用于存储某个节点权值,ch_qz_ini用于初使化
FILE *fp=NULL;
//if((fp=fopen("e:\\topology.txt", "r"))==NULL) ///打开存储权值的文件
if((fp=fopen("topology1.txt", "r"))==NULL) ///打开存储权值的文件
{
//printf("文件打开失败!\n");
return 0;
}
//printf("文件打开成功!\n");
////读文件,从文件中每次读取一个字符
ch_read=fgetc(fp);
ch_qz[0]=ch_read;
i=0;////数组行下标
j=0;///数组列下标
while(ch_read!=EOF)
{
//if (ch==10) printf("\n放行回车");
//if (ch==32) printf("\n这是空格");
ch_read=fgetc(fp);
str[0]=ch_read;
if ((ch_read==32) || (ch_read==10))
{
topo[i][j]=atoi(ch_qz);
j++;
if (ch_read==10) ///新行开始
{
i++;
j=0;
}
ch_qz[0]=ch_qz_ini[0];
// ch_qz[1]=ch_qz_ini[1];
// ch_qz[2]=ch_qz_ini[2];
// ch_qz[3]=ch_qz_ini[3];
}
else
{
strcat(ch_qz,str); ///合并
}
}
fclose(fp);
return 1;
}
用visual C++ 2008运行时出现如下问题:
用VC6.0运行时,拓扑打印有误(最后一个数字打印错误)
原始矩阵为
相关文章推荐
- C语言求矩阵偶数的平均值和程序输出某数的问题
- C# 编译器选项 /platform(指定输出平台)32位程序运行到x64平台的问题
- Python IDE: PyCharm程序输出乱码问题(含中文乱码)
- 按矩阵对角线输出问题
- 写程序输出8皇后问题的所有排列,要求使用非递归的深度优先遍历。
- 按矩阵对角线输出问题
- 写程序输出8皇后问题的所有排列,要求使用非递归的深度优先遍历。
- qt简单的hello world测试程序终端无输出问题
- 从易到难编写C++程序,(8)问题:实现一个矩阵类
- 求利用邻接矩阵求多有节点最短路径的java程序 可运行
- 编程珠玑: 12章 取样问题 12.3设计空间,程序的输入包含两个整数m和n,其中m<n。输出是0~n-1范围内m个随机整数的有序列表,不允许重复。 解法2-------解题总结
- 问题三十五: 编程序输出各种星号图(一)
- 素数距离问题 时间限制:3000 ms | 内存限制:65535 KB 难度:2 描述 现在给出你一些数,要求你写出一个程序,输出这些整数相邻最近的素数,并输出其相距长度。如果左右有等距离长度素数
- java__晓萌最近在做一个翻转图片的应用,你可能也知道,图片其实是由一个个的点组成的。于是,晓萌想先做一个可以翻转矩阵的程序,来解决他问题的核心部分。
- C# 输出矩阵中的正负数对齐问题记录
- Web程序中利用web.config解决无法输出excel页面的问题
- 程序中遇到的问题 输出2位数 不足在前面补0
- 在 Sublime Text 2 中编译和运行 Java 程序,以及输出中文出错问题解决办法
- 程序算法艺术与实践:递归策略之矩阵乘法问题
- 数据结构,图的邻接矩阵创建,邻接矩阵与邻接表的交换,两种表的输出,过程用C++实现