Tag: arrays

如何在C中旋转1d数组的一部分?

我打印出一个6×6 1darrays,但想要逆时针旋转左上角3×3部分。 有算法吗? 将来我也想像右下3×3部分或右上3×3部分或左下3×3部分一样旋转。 a[0] a[1] a[2] a[3] a[4] a[5] a[1] a[2] a[8] a[3] a[4] a[5] a[6] a[7] a[8] a[9] a[10] a[11] a[0] a[7] a[14] a[9] a[10] a[11] a[12] a[13] a[14] a[15] a[16] a[17] —> a[6] a[12] a[13] a[18] a[19] a[20] a[18] a[19] a[20] a[21] a[22] a[23] a[18] a[19] a[20] a[21] a[22] a[23] a[24] a[25] […]

删除char数组中的第一个标记,并将其余标记保留在C中

所以如果我在C中有以下char数组: “abc” // where “a”, “b”, and “c” can be char arrays of any length and the // space between them can be of any length 如何删除“a”标记但将其余的“bc”存储在char指针中? 到目前为止,我已经实现了以下不起作用的方法: char* removeAFromABC(char* a, char* abc) { char* abcWithoutA[MAXIMUM_LINE_LENGTH + 1]; int numberOfCharsInA = strlen(a); strcpy(abcWithoutA, (abc + numberOfCharsInA)); return abcWithoutA; }

为什么“gcc-std = c99 ……”不允许我使用VLA?

我正在尝试使用以下代码编译 gcc -c -g -std = c99 -MMD -MP -MF“build / Debug / Cygwin_4.x-Windows / main.od”-o build / Debug / Cygwin_4.x-Windows / main.o main.cpp 下面的代码在函数func中使用VLA,我认为应该由c99支持,我相信我通过标志-std = c99使用。 问题是,当我运行此操作时,我收到以下警告和错误: cc1plus:警告:命令行选项’-std = c99’对C / ObjC有效但对C ++无效 main.cpp:11:35:错误:在’]’之前使用函数体外的参数令牌void func(int a,int b,int arry [a] [b]){^ main.cpp:11:38:错误:在’]’之前使用函数体外的参数令牌void func(int a,int b,int arry [a] [b]){ 第一个警告让我怀疑gcc是否正在尝试将代码编译为c或c ++。 第二个让我觉得使用VLAfunction有问题,虽然我的理解是c99应该支持。 代码是: void func(int a, […]

C,多维数组练习

我对二维数组的理解是错误的。 所以我会以另一种方式处理这个问题。 说我有以下变量。 int student_id[10], course_id[5]; int student_course[10][2]; 只有10名学生。 只能有5门课程。 学生只能参加2门课程。 /*prompt user for student id*/ /* say that the value for: student_id[0]=123 */ /*prompt user for course id*/ /* say that the value for: course_id[0]=101 course_id[1]=102 course_id[2]=103 course_id[3]=104 course_id[4]=105 */ 我要打印的是 student_course[value_of_student_id][value_of_course_id] 。 所以我想这样做: int student_id[10], course_id[5], student_course[10][2] int i, j, k; for(i=0; i<10;i++){ […]

使用数组的队列

下面是我使用数组实现的简单队列。 #include #include #define QSIZE 5 //Limit size of queue to just 5 enteries /*Beginning of prototype for queue functions: Insert, retrieve and display*/ void qdisp(); //Display to queue array contents void qinsert(); //Insert a element into rear of queue int qdelete(); //Remove an element from front of queue /*End of prototyping*/ // Variables int […]

如何在MIPS汇编中初始化一个巨大的数组?

例如,我正在尝试将C代码转换为等效的MIPS: int a[50]; int i; … a[0] = 1; a[1] = 1; … 看看其中一个答案 ,除此之外别无他法吗?: .data array: .word 1,1,…,0 (till the 50th zero)

在dsPIC33上吻合FFT

我一直试图让KissFFT在dsPIC上工作,但是在尝试了各种不同的方法之后,输出并不是应该的。 我希望得到一些帮助,看看是否有任何我可能会忽略的配置,或者它是否只是我没有想到的东西? 我在MPLABX中使用dsPIC33EP256MC202和XC16编译器。 声明和内存分配。 int readings[3] = {0, 0, 0}; kiss_fft_scalar zero; memset(&zero,0,sizeof(zero)); int size = 128 * 2; float fin[256]; kiss_fft_cpx in[size]; kiss_fft_cpx out[size]; for (i = 0; i < size; i++) { in[i].r = zero; in[i].i = zero; out[i].r = zero; out[i].i = zero; } kiss_fft_cfg mycfg = kiss_fft_alloc(size*2 ,0 ,NULL,NULL); 从面包板上的accellerometer读取读数并填充浮子arrays(使用毕达哥拉斯将3轴合并为一个信号)。 输入XYZ值按比例缩小,平均值介于-2400和2400之间。 […]

将行拆分为单词+ C的数组

我试图将一行分成一系列单词,但我仍然坚持如何在C中这样做。我的C技能不是很好,所以我想不出一种方法来“执行”我的想法。 她是我迄今为止所拥有的: int beginIndex = 0; int endIndex = 0; int maxWords = 10; while (1) { while (!isspace(str)) { endIndex++; } char *tmp = (string from ‘str’ from beginIndex to endIndex) arr[wordCnt] = tmp; wordCnt++; beginIndex = endIndex; if (wordCnt = maxWords) { return; } } 在我的方法中,我收到(char * str,char * arr [10]),str是我想要在遇到空格时要拆分的行。 arr是我想要存储单词的数组。 有没有办法将我想要的’chunk’的’chunk’复制到我的tmp变量中? […]

将Fortran整数数组传递给C子例程仅传递第一个元素

我试图将一个整数数组从Fortran传递给C,但我只能传递数组的第一个元素。 我有下面的测试程序再现错误。 我哪里错了? program test use foo integer (kind=c_int), allocatable :: hgmu_dose(:) allocate (hgmu_dose(0:10)) HGMU_dose(0)=22 HGMU_dose(1)=2 HGMU_dose(2)=3 HGMU_dose(3)=4 HGMU_dose(4)=5 HGMU_dose(5)=6 HGMU_dose(6)=7 HGMU_dose(7)=8 HGMU_dose(8)=9 HGMU_dose(9)=10 HGMU_dose(10)=11 print *, “HGMU_dose=”, hgmu_dose call test_interface(hgmu_dose) end program module foo use ISO_C_Binding implicit none interface subroutine test_interface(dose) bind(C,name=”INTERFACE”) import :: c_int import :: c_double import :: c_char integer (kind=c_int), allocatable […]

从Fortran传递2d数组到C

我很难将Fortard中的二维数组传递给C函数。 但是,在所有支持之后,以下代码100%正常运行。 以下是我的C函数: #include void print2(void *p, int n) { printf(“Array from C is \n”); double *dptr; dptr = (double *)p; for (int i = 0; i < n; i++) { for (int j = 0; j<n; j++) printf("%.6g \t",dptr[i*n+j]); printf("\n"); } } 以下是我的Fortran代码: program linkFwithC use iso_c_binding implicit none interface subroutine my_routine(p,r) bind(c,name=’print2′) import […]