c - C 头文件和#define 指令
问题描述
头文件名为 myh.h。在这个程序中,如何在这个数组中存储更多的#define 值作为 p[]?存储了两个值,如何在给出注释的主函数中访问这些值?程序中存在编译错误。
#include <stdio.h>
#include <string.h>
#define p [] { "parthinb ", "baraiyab " }
#define u "parthin"
int account(char name[10])
{
printf("Welcome %s", name);
return 0;
}
#include <stdio.h>
#include <conio.h>
#include <string.h>
#include "myh.h"
int main()
{
char un[20], pass[10], c;
int i;
start:
printf("Enter USER NAME::");
gets(un);
printf("Enter Password of 8 Digitis::");
for (i = 0; i < 8; i++)
{
c = getch();
pass[i] = c;
c = '*';
printf("%c", c);
}
pass[i] = ' ';
if (strcmp(un, u) == 0)
{
if (strcmp(pass, p[]) == 0)
{
printf("\nCORRECT\n");
account(un);
}
else
{
printf("\nPassword mis-match\n");
goto start;
}
}
else
{
printf("\nUSER Name or password does not match.\n");
goto start;
}
}
解决方案
您不能使用 #define 来存储 char* 数组。检查此链接。如果您以后不需要更改它,您可以将数组定义为 const:
const char* p[] = {"parthinb ", "baraiyab "};
您可以使用其索引访问 p 的每个元素:
p[index_of_that_element]
推荐阅读
- python - 在python中获取spark提交作业的结果
- javascript - 使用正则表达式按键名提取 javascript 对象值
- sql - 创建一个索引,防止客户重复订单
- ios - 钥匙串项目更新时的NSInternalInconsistencyException
- powershell - PowerShell:对 CPU 使用率进行排序以显示占用 2% 及以上的进程
- python - Python Speech_Recognition - “这个音频源已经在上下文管理器中”
- java - 当类在类路径上时,Surefire 抛出 SurefireReflectionException
- python - 如何根据数据帧(pydub/python)中指定的起始/偏移量分割一系列录音
- ruby-on-rails - 如何在关注中使用枚举
- javascript - 来自视频和音频元素的声音不在 iOS 上播放(不是自动播放问题)