int inspectpass(char password[17])//检验输入的密码是否正确 { FILE *p; char sign,s[16]; int len,i; len=strlen(password); if(len<6||len>16) return 0; p=fopen("password.txt","r"); for(;feof(p)==0;) { sign=fgetc(p); if(sign==seat[0]) { for(i=0;feof(p)==0;i++) { s[i]=fgetc(p); if(s[i]=='#') { s[i]='\0'; break;}} if(strcmp(s,password)==0) return 1; else return 0;}} } //!!!!!!!!!! int inspectnum(char number[17])//检验输入的账号文件中是否存在 { FILE *p; char sign,s[17]; int len,i; len=strlen(number); if(len<6||len>16) return 0; p=fopen("number.txt","r"); for(;feof(p)==0;) { sign=fgetc(p); if(sign<'A'||sign>'Z') return 0; for(i=0;feof(p)==0;i++) { s[i]=fgetc(p); if(s[i]=='#') { s[i]='\0'; break;}} if(strcmp(s,number)==0) { seat[0]=sign; return 1;} else { set=sign+1; fgetc(p);}} return 0; } //!!!!!!!! void logon()//注册系统主界面 { char home(); FILE *p; char number[16],password[16]; int len; system("cls"); printf("\t注册系统!\n\n设置账号(6~16位数字或字符):\n"); G: scanf("%s",&number); len=strlen(number); if(len>=6&&len<=16) { if(inspectnum(number)==1) { printf("账户已存在!请重新设置:"); goto G;} else { p=fopen("number.txt","a"); fputc(set,p); fputs(number,p); fputc('#',p); fputc('\n',p); fclose(p);}} else { printf("输入错误!请重新设置:"); goto G;} printf("\n设置密码(6~16位非纯数字,不含空格):\n"); H: scanf("%s",&password); len=strlen(password); if(len<6||len>16) { printf("输入错误!请重新设置:"); goto H;} else { p=fopen("password.txt","a"); fputc(set,p); fputs(password,p); fputc('#',p); fputc('\n',p); fclose(p);} system("cls"); printf("注册成功!自动返回主界面!\n"); home(); } //!!!!!!!!!!
时间: 2023-06-01 16:04:36 浏览: 72
座') break; } s[i]='\0'; if(strcmp(password,s)==0) { fclose(p); return 1; } } } fclose(p); return 0; }
这段代码是一个函数,函数名为inspectpass,作用是检验输入的密码是否正确。函数有一个参数password,它是一个长度为17的字符数组,用来存储输入的密码。函数返回一个整数值,如果密码正确则返回1,否则返回0。
函数首先会判断输入的密码长度是否在6到16之间,如果不是则直接返回0。然后函数会打开一个名为password.txt的文件,并逐个读取文件中的字符。当读到字符“座”时,函数会把前面读取的字符存储到字符串s中,并将其与输入的密码进行比较。如果相同,则返回1,否则继续读取文件,直到文件结束为止。最后函数会关闭文件并返回0。
相关问题
介绍一下struct _mat_t { void *fp; /< File pointer for the MAT file */ char *header; /< MAT file header string */ char *subsys_offset; /< Offset */ char *filename; /< Filename of the MAT file */ int version; /< MAT file version */ int byteswap; /< 1 if byte swapping is required, 0 otherwise */ int mode; /< Access mode */ mat_off_t bof; /< Beginning of file not including any header */ size_t next_index; /< Index/File position of next variable to read */ size_t num_datasets; /< Number of datasets in the file */ #if defined(MAT73) && MAT73 hid_t refs_id; /**< Id of the /#refs# group in HDF5 */ #endif char dir; /< Names of the datasets in the file */ };每个参数的意义
- `void *fp`: 文件指针,用于访问MATLAB文件。
- `char *header`: MATLAB文件的文件头字符串。
- `char *subsys_offset`: 文件中的偏移量。
- `char *filename`: MATLAB文件的文件名。
- `int version`: MATLAB文件版本号。
- `int byteswap`: 标记是否需要进行字节交换。
- `int mode`: 文件访问模式。
- `mat_off_t bof`: 文件的开始位置(不包括文件头)。
- `size_t next_index`: 下一个变量的索引/文件位置。
- `size_t num_datasets`: 文件中数据集的数量。
- `hid_t refs_id` (仅限MATLAB 7.3及更高版本): HDF5数据集的ID。
- `char **dir`: 文件中数据集的名称。
int*p=new char[5]是正确的吗
这段代码是合法的,但是并不是正确的。这是因为 p 是一个 int 类型的指针,而 new char[5] 分配的是 5 个 char 类型的内存空间。当我们将这个 char 类型的指针赋值给 int 类型的指针 p 时,会发生指针类型不匹配的问题,这会导致程序出现未定义的行为。
正确的做法是,将 p 声明为 char 类型的指针,或者将 new 操作符后面的类型改为 int 类型,例如:
```
char* p = new char[5]; // 将 p 声明为 char 类型的指针
int* p = new int[5]; // 将 new 操作符后面的类型改为 int 类型
```
这样,就可以避免指针类型不匹配的问题。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)