Tag: 数组

PHP中的字符串是一个字符数组吗?

就像在C中一样,我可以使用字符串作为数组吗? 例如 $a=”abcd”; for($b=0;$b<=3;$b++) {echo $a[$b];} 那么,PHP中的字符串是一个数组,还是基于C中的数组?

在C函数中对数组进行排序

所以我需要将数组传递给函数sort并对它进行排序,它在外面工作,但不能让它在函数内部工作。 需要传递的指针只是不确定如何。 #include void sort(int *number, int n) { /* Sort the given array number, of length n */ int temp = 0, j, i; for (i = 1; i < n; i++) { for (j = 0; j number[j + 1]) { temp = number[j]; number[j] = number[j + 1]; number[j + 1] = […]

如何在函数之间传递数组

有人能帮我吗? 我遇到了C程序的问题。 这里是: 在我的主要部分,我调用一个函数(func A),其中两个参数是第二个函数(fun B)和“user data”(原则上可以是单个数字,char或数组)。 这个“用户数据”也是函数B的一个参数。当“用户数据”是一个整数但是现在我需要将它用作数组时,我已经完成了所有工作。 所以目前的工作结构是这样的: static int FunB(…,void *userdata_) { int *a=userdata_; … (here I use *a that in this case will be 47) … } int main() { int b=47; funcA(…,FunB,&b) } 所以现在我希望b在main中作为一个数组(例如{3,45}),以便将更多的单个“数据”传递给函数B. 谢谢

为什么这个联合正在删除c代码中数组中的第一条记录?

这是我的一个头文件,它由一个包含4种不同结构的联合模板组成。 #define MAX 3 union family { struct name /*for taking the name and gender of original member*/ { unsigned char *namess; unsigned int gender; union family *ptr_ancestor; /*this is a pointer to his ancestors details*/ }names; struct male /*for taking the above person’s 3 male ancestors details if he is male*/ { unsigned char […]

如何将无符号字符数组转换为C中的字符串?

如果我有这样的数组 unsigned char data[2850] = “”; 在运行我的程序的一部分之后,最终会充满字节元素,这样如果我遍历它并将其记录下来,我会看到以下内容 for (size_t i= 0; i < sizeof(data); i++) { printf("%02X ", data[i]); } //log window shows 01 24 81 00 0E 1C 44 etc… 有没有办法获取数据数组的所有元素并将它们放入const char? 或者只是一个大字符串? 希望我足够清楚。 我的目标是最终将此数据数组的所有元素转换为base64编码的字符串,我可以在程序中的其他位置使用。

memcpy()从较小的数组到较大的数组

我找不到任何关于这个问题的提法。 我有一个结构数组,我需要resize的数组。 两个结构都已完全初始化(每个单元格的值都不是NULL) 说 typedef struct Square { … … }Square; Square s1[1024]; Square s2[2048]; 如果我使用memcpy() s1复制到s2中,s2会怎么样? 我知道它复制字节数据。 将前1024个单元格与s1相同,剩下的1024个单元格将在初始化时生效吗? 还是会影响他们? 谢谢 PS这里的数组是静态分配的,但我写的只是为了方便。 我使用malloc()分配它们

将值附加到动态数组的末尾

好吧,我在这个寒假期间一直在研究一点C,在我的冒险经历中,我偶然发现了动态arrays的问题。 这真的是一个相当简单的程序。 我想要做的是创建一个包含斐波那契数列的数组。 这是代码: #include #include int dynamic_arry_append(int* arry, int* number, int* size); int main() { int i, n, size = 3, *arry = NULL, fibarr[size]; printf(“Dynamic array, Fibonacci series. \n”); printf(“Capture upto element: “); scanf(“%d”, &n); i = 0; // passing the first elements fibarr[0] = 0; fibarr[1] = 1; fibarr[2] = 1; while […]

在C中使用qSort排序的数组字符串

问题很简单:有一些方法可以反过来返回返回“qsort”的有序数组,即我想避免使用任何辅助数组来使用qsort投资生成的数组。 这是我的代码,它从要排序的标准输入字符串中读取,并使用比较函数进行排序。 #include #include #include #include #include int cstring_cmp(const void *a, const void *b) { const char **ia = (const char **)a; const char **ib = (const char **)b; return strcasecmp(*ia, *ib); /* strcmp functions works exactly as expected from comparison function */ } 在此先感谢您的回复,对不起我的英语 int main (int argc, char *argv []) { int number; […]

在这个C拼图中要替换什么?

现在这是我从一些试卷中得到的一个愚蠢的谜题,遗憾的是我无法在过去的15分钟内弄明白。 #include int main(void){ /* */ putchar(*(wer[1]+1)); return 0; } 为了获得输出e我们应该用什么替换代替。现在我们知道putchar将int作为参数,但是这段代码假设给出一个指针。这个问题是否有效?

计算数组中当前元素右侧的更多元素

我试图计算元素的数量大于数组右侧的元素。 我的function在这里。 int* SurpassersKing(int input1_size, int* input1,int* output_size) { int i,k; int count[input1_size]; for (i = 0; i < input1_size; i++) count[i] = 0; for ( i = 0; i < input1_size; i++) { for ( k = i + 1; k <input1_size; k++) { if (input1[i] < input1[k]) { count[i]++; } } } return […]