• 闪存
• 博客
• 发言 小组
• 投递 新闻
• 提问 博问
• 添加 收藏
• 发布 招聘
• 文库

# 关于c语言fopen函数的问题

0 悬赏园豆：20 [待解决问题] int matrix()/* 生成可逆矩阵 */
{
int det,i,j;
int **mat;
FILE *fp;

if((fp=fopen("mat.txt","a+")) == NULL)
{
printf("\nFailed to open the file.\n");
exit(1);
}
srand(time(NULL));

mat = (int **)malloc(ORDER_M * sizeof(int *));
for(i = 0;i < ORDER_M;i++)
mat[i] = (int *)malloc(ORDER_M * sizeof(int));
for(i = 0;i < ORDER_M;i++)
{
for(j = 0;j < ORDER_M;j++)
{
mat[i][j] = rand() % MOD_M;
fprintf(fp,"%4d",mat[i][j]);
}fprintf(fp,"\n");
}

det = detmat(mat,ORDER_M);
if(det % 2 == 0||det % 13 == 0||det == 0)
status = 0;
else
status = 1;
fclose(fp);
while(!status)/* 判断矩阵是否可逆，不可逆则重新随机生成一个矩阵，并进行再判断 */
det=matrix();

for(i = 0;i < ORDER_M;i++)
free(*(mat+i));
free(mat);
return det;
}

0

"w"

Opens an empty file for writing. If the given file exists, its contents are destroyed.

"w+"

Opens an empty file for both reading and writing. If the given file exists, its contents are destroyed.

"a+"

Opens for reading and appending; the appending operation includes the removal of the EOF marker before new data is written to the file and the EOF marker is restored after writing is complete; creates the file first if it doesn’t exist.

0

您需要登录以后才能回答，未注册用户请先注册