Tag: 赋值

在C中为const char *分配一个define常量

我不完全确定哪个是将常量赋给const char *的正确方法。 两种方式都可以吗? #define MSG1 “My Message #1” #define MSG2 “My Message #2” #define MSG3 “My Message #3” const char *opt1 = NULL; const char opt2[20]; switch(n){ case 1: opt1 = MSG1; // or should it be: strcpy(opt2, MSG1); break; case 2: opt1 = MSG2; // or should it be: strcpy(opt2, MSG2); break; case […]

如何在创建它时将多个值一次分配给多维数组 – 在C?

我正在用C编程并想知道是否可以一次为多维数组分配多个值? 我尝试了一些技术,但都失败了! 我不想循环遍历数组来赋值(我想要禁食的方式为数组中的所有索引赋值)。 我正在使用的数组:ary [4] [4]。

我无法将char字符串分配给char数组

这就是我现在拥有的。 void insert(char Table[][81], char Key[81]){ int index; index = search(Table, Key); // This is another function used to find an empty ‘slot’ // in the table if(Table[index] == ‘\0′) Table[index] = Key; // <– This is the line that contains some sort of error. else printf("ERROR: Key already in Table\n"); } 它抛出的错误是: 从类型’char *’分配类型’char […]

在C中,为什么我不能在声明后将字符串赋值给char数组?

这一直困扰着我。 struct person { char name[15]; int age; }; struct person me; me.name = “nikol”; 当我编译时,我收到此错误: 错误:从类型’char *’分配类型’char [15]’时出现不兼容的类型 我错过了一些明显的东西吗?