如何让程序做如下的检测
计划让程序做如下的检测:附上代码如下:
程序代码:
#include <stdio.h> #include <stdlib.h> #include <string.h> char * Mystrrev (char * str ); int main() { char str[33]; int System; int n,x,y; FILE *fp; if ((fp = fopen ("D:\\wenjian.txt", "a+")) == NULL) { printf("打开文件失败\n"); exit(1); } printf("请输入本次填充数据的进制:(2~9)\n"); printf("进制 :"); scanf("%d",&System); printf("请输入本次生成数据的组数:(0`n)\n"); printf(" n = "); scanf("%d",&n); printf("请输入本次生成数据的数组大小:\n"); printf(" 行 x= "); scanf("%d",&x); printf(" 列 y= "); scanf("%d",&y); int Data[n][x][y]; for (int i = 0 ; i < n ; i++ ) { itoa(i, str, System); int Str_length = strlen(str); char str_tem[33]; char str_tem1[33]; memset(str_tem,'0',33); int Data_x_length = (x-1)/2+(x-1)%2; if ( Data_x_length >= Str_length) str_tem[Data_x_length - Str_length] ='\0'; else { printf("数组太小,请检查你的设置参数!"); return -1; } strcat(str_tem,str); strcpy( str_tem1, str_tem); Mystrrev (str_tem1); if (x%2) strcat( str_tem1, str_tem); else { str_tem1[strlen(str_tem1)-1] ='\0'; strcat( str_tem1, str_tem); } for (int ay=0;ay < y; ay++) Data[i][0][ay] = ay+1; for (int ax=1;ax < x;ax++) for (int ay=0;ay < y;ay++) Data[i][ax][ay] =str_tem1[ax-1]- '0'; } for (int an=0;an < n;an++) { fprintf(fp,"n = %4d\n",an); for (int ax = 0;ax < x ; ax++) { for (int ay = 0;ay < y;ay++) fprintf(fp,"%4d",Data[an][ax][ay]); fprintf(fp,"\n"); } fprintf(fp,"\n"); } fclose(fp); return 0; } char * Mystrrev (char * str ) { char *start = str; char *left = str; char ch; while (*str++); str -= 2; while (left < str) { ch = *left; *left++ = *str; *str-- = ch; } return(start); }
为啥当代码运行到
请输入本次生成数据的数组大小 行
选择第20行(含21行以后的行数)的时候,输出的文件是空文件呢?文件没有内容。这个文件不应该是空文件哦。