C 头文件和#define 指令
C header files, and #define directive
头文件名称为 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;
}
}
从表面上看,您可以只定义将 p 值列表存储在变量中,并避免使用“#define”
static char *p[] = { "parthinb ", "baraiyab " } ;
可以参考strcmp中的p[i]等
您不能使用#define 来存储char* 数组。检查 this link。
如果您以后不需要更改它,您可以将数组定义为常量:
const char* p[] = {"parthinb ", "baraiyab "};
并且您可以使用其索引访问 p 的每个元素:
p[index_of_that_element]
头文件名称为 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;
}
}
从表面上看,您可以只定义将 p 值列表存储在变量中,并避免使用“#define”
static char *p[] = { "parthinb ", "baraiyab " } ;
可以参考strcmp中的p[i]等
您不能使用#define 来存储char* 数组。检查 this link。 如果您以后不需要更改它,您可以将数组定义为常量:
const char* p[] = {"parthinb ", "baraiyab "};
并且您可以使用其索引访问 p 的每个元素:
p[index_of_that_element]