malloc

    -7熱度

    1回答

    我想知道如果動態分配內存我使用新的[]或malloc在std :: vector,或不需要,如果我不需要,我應該在哪裏使用new [],malloc和smartpointers?

    0熱度

    2回答

    我試圖製作一個使用二維數組作爲其級別基礎的遊戲。但是,它的大小需要能夠在不同層次上變化。 經過一番研究,我發現this question似乎與我有同樣的問題。我試過儘可能地應用它: typedef struct level{ /*other stuff*/ int Size; int Arr[0][0]; }level; level InitLevel(in

    0熱度

    4回答

    char * removeChar(char * str, char c){ int len = strlen(str); int i = 0; int j = 0; char * copy = malloc(sizeof(char) * (len + 1)); while(i < len){ if(str[i] != c){

    -1熱度

    1回答

    我堅持指針的基礎知識的malloc這裏是我的代碼 char *orderUp; orderdup = malloc(10 * sizeof(char)); printf("enter string"); scanf("\n%s",orderdup); printf("\n%s",orderdup);// gives scanned strings printf("\n%s",*ord

    0熱度

    1回答

    我想學習c主函數調用一些其他函數返回一個數組(例如字符串類型)。 #include <stdio.h> #include <stdlib.h> #include <string.h> char* array_return(char* name); int main(){ char* name="orange"; char* A; A=array_retur

    -1熱度

    2回答

    我不知道用malloc加入陣列什麼錯我的代碼,但IM的 屏幕上會出現「總和」的值相同.. 假設m和n等於進入.... enter image description here #include<stdio.h> #include<malloc.h> #include<iostream> #include<stdlib.h> using namespace std; int main()

    -1熱度

    2回答

    我遇到了動態創建char數組的問題。 下面的代碼是導致這些問題的例子: #include <stdio.h> #include <stdlib.h> #include <string.h> int main (void){ char** top = NULL; top = malloc(30*sizeof(char)); printf("sizeof

    -1熱度

    2回答

    #include <stdio.h> #include <stdlib.h> #include <stdbool.h> #include <string.h> typedef struct _person { char *fname; char *lname; bool isavailable; }Person; Person *getPerson

    2熱度

    1回答

    我正在爲模擬編程樹算法。每個處理器都有自己的樹。在程序中的特定點,我必須檢查是否有特定樹中的粒子不屬於那裏。我收集它們並將它們發送到正確的樹/處理器。 我的問題是關於我收集粒子並將它們放入動態大小列表的過程。由於我必須發送給另一棵樹的粒子數量不是恆定的,我必須使用動態數組。 我實現了一個小程序,所有這些都應該發生。但它只適用於小型N。但也爲小N有時會出現錯誤。重新分配過程可能不起作用。 #incl

    -1熱度

    1回答

    這裏有人問了關於||運營商的問題。他想知道爲什麼(j=3) || (i=3)沒有把3分配給我。那個帖子是在這裏:Determining the print of C 在我的第一個問題的答案我給這個例子對於如何「功能」可用於: ptr = malloc(sizeof(*ptr)) || printf("Error\n"); 是的,我知道它應該被打印到標準錯誤,但這不是話題。如果我記得正確,我被告