大佬教程收集整理的这篇文章主要介绍了读取矩阵中的整数,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
#include<stdio.h>
#include<String.h>
#include<stdlib.h>
#define N 512
int main(){
file *inputfile;
inputfile=fopen("abc.txt","r+");
int mat[n][n];
int j=0;
int i;
int c; /* Character */
int cp; /* PrevIoUs Character */
int n; /* number of lines */
n = 0;
c = 0;
int k=0;
if(inputfile==NulL){
printf("error");
}
while (1) //this calculate line number
{
cp = c;
c = getc(inputfilE);
if(c == ' '){
k++;
}
if (c == '\n')
{
n++;
conTinue;
}
if (c == EOF && cp == '\n') break;
if (c == EOF)
{
n++;
break;
}
}
for(i=0;i<n-1;i++){
for(j=0;j<15;j++){
fscanf(inputfile,"%d",&mat[i][j]);
}
}
printf("%d",mat[0][9]);
return 0;
}
我有一个这样的文件:
1 5 3 6 9 8 5 4 7 8 9 6 4 1 2
1 2 36 5 4 7 8 9 54 5 6 5 2 1 5
2 54 65 32 14 52 14 52 362 55 23 84 1 1 1
我需要:
...
mat[0][0]=1;
mat[0][1]=5;
...
我尝试将这些整数从文件中读取到矩阵中。我怎样才能做到这一点? (我的大问题是尝试使用 512x512 文件时没有出现错误。)
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)
以上是大佬教程为你收集整理的读取矩阵中的整数全部内容,希望文章能够帮你解决读取矩阵中的整数所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。