Tag: c

输入scanf数组,递归函数没有循环(.c)

用户得到我的数组大小,我分配了函数“MALLOC”的内存分配,只用递归输入数组,没有循环!! 我不知道如何用递归函数创建一个“循环”。 我希望很高兴能得到帮助。 谢谢。

为什么降低优先级运算符首先执行?

可能重复: 运算符优先级问题 我们知道前缀的优先级大于“LOGICAL AND”( && ),“LOGICAL AND”的优先级大于“LOGICAL OR”( || )。 以下程序似乎违反了它: int main() { int i=-3,j=2,k=0,m; m=++i||++j&&++k; printf(“%d %d %d %d”,i,j,k,m); return 0; } 如果++优先级大于&&和|| 然后所有前缀应首先执行。 在此之后i=-2,j=3,k=1然后&&将首先执行。 为什么输出显示: -2 2 0 1 ? 该程序的行为在ubuntu v12.04上也是相同的。

在C中使用sizeof()运算符时出现奇怪的情况

我正在使用以下代码测试在C / C ++中使用sizeof运算符: #include /* Character types */ #include /* Standard buffered input/output */ #include /* Standard library functions */ #include /* String operations */ #include /* Data types */ #include /* Declarations for waiting */ #include void main() { char a[100]; char *des = malloc(100*sizeof(char)); strcpy(des,”abcded\0″); printf(“%d\n”,sizeof(des)); printf(“%d\n”,sizeof(a)); free(des); } 为什么这个程序输出: 4 100 […]

将三重指针传递给函数然后mallocing一个二维数组

得到分段错误并且不明白为什么,必须传递三重指针才能进行分配,所以无法改变… 这是function void alloc2d(double*** a, int m, int n) { int i, j; **a = malloc(sizeof(double *) * m); a[0] = malloc(sizeof(double) * n * m); for(i = 0; i < m; i++) a[i] = (*a + n * i); } 这是函数的调用…… double** m; alloc2d(&m, 5, 10); double count = 0.0; for (int i = […]

函数返回无穷大的字符串导致嵌入式编译器

我正在尝试执行字符串到双重转换。 在gnu c编译器中我得到了正确的值。 但是如果我在我的嵌入式编译器(renesas CS +)中使用它,它会给出未定义的行为,比如返回无穷大的结果。 这是我的代码: double str_to_double_func(char a[]) { char str[30] = {‘0′}; int loop ; double result; int len ; int pos,n; for(loop = 0;a[loop]!=’\0’;loop++) { str[loop] = a[loop]; } str[loop] = ‘\0’; pos = 0; len = sizeof(str)-1; for (n = 0; n < len; n++) { if (str[n] == '.') […]

读写矩阵

我写了这段代码来输入r * c矩阵 r – >行c – >列 当r c时无法产生正确的输出。 例: r = 6,c = 2 输入:1 2 3 4 5 6 7 8 9 10 11 12 输出: 1 2 11 12 5 6 11 12 11 12 11 12 请告诉我我哪里出错了。 我不想使用恒定大小的数组。 #include void scanmatrix(int* a[],int r,int c) { int i,j; for(i=0;i<r;i++) { for(j=0;j<c;j++) […]

编译器错误,我无法找到

我收到一个我无法解决的错误。 我彻底完成了我的代码但没有成功。 我究竟做错了什么? 见下面的代码。 编译错误: In function ‘main’: ou1.c:49:1: error: expected ‘while’ before ‘printf’ printf(“End of program!\n”); ^ 我的代码: #include int main(void){ int choice; float price, sum, SUMusd; float rate =1; printf(“Your shopping assistant”); do{ printf(“1. Set exchange rate in usd (currency rate:%f)\n”, rate); printf(“2. Read prices in the foreign currency\n”); printf(“3. End\n”); printf(“\n”); scanf(“%d”, […]

LibVLC空图像

我正在尝试使用LibVLC解码video文件并将其渲染为纹理。 打开和开始播放的代码工作,音频播放完美,但像素缓冲区始终填充0xCD。 我尝试在VLC上渲染的video,甚至在C#实现中我都做到了,但是CI中的这个新代码无法让它工作…… 我正在使用x64版本的vlc库,如果这有任何区别,程序将编译为x64。 这是我的代码: #include “stdafx.h” #include “video.h” #include #include #include #include libvlc_instance_t* instance; libvlc_media_t* media; libvlc_media_player_t* player; struct videoContext { unsigned char *pixeldata; unsigned char currentFrame; int width; int height; }; struct videoContext mainContext; bool gotData = false; int width; int height; static void *lock(void *data, void **p_pixels) { videoContext* context = (videoContext*)data; […]

无法配置交流编译器

我正在尝试使用gcc 4.7编译一些库(我刚从4.6.3升级,不知何故它抱怨c编译器: /home/rtbkit/platform-deps/node/wscript:263: error: could not configure ac compiler! make[1]: Entering directory `/home/rtbkit/platform-deps/node’ Project not configured (run ‘waf configure’ first) make[1]: *** [program] Error 1 make[1]: Target `all’ not remade because of errors. make[1]: Leaving directory `/home/rtbkit/platform-deps/node’ make[1]: Entering directory `/home/rtbkit/platform-deps/node’ Project not configured (run ‘waf configure’ first) make[1]: *** [program] Error 1 make[1]: Target […]

如何从链表中弹出元素?

我正在尝试使用各种推送和弹出function来学习链表,但我无法从链表中的尾部弹出元素。 任何人都可以帮我解决popBackfunction吗? 我尝试过类似的东西: typedef struct { float val; }data; typedef struct nodePtr { struct nodePtr *next; data *d; }node; typedef struct { node *head; node *tail; }linkList; linkList* createlinkList() { linkList *ll = (linkList*)malloc(sizeof(linkList)); ll->head = NULL; ll->tail = NULL; return ll; } node* createNode(data *d) { node *nd = (node*)malloc(sizeof(node)); nd-> d = d; […]