Binary Tree with parent nodes are the minimum of 2 children of them
Stack Overflow » C#
by ahnherin092
48m ago
A binary tree can sort n elements of an array of data. First, create a complete binary tree with all leaves at one level, whose height h = (log2 n) + 1, and store all array elements in the first n leaves. In each empty leaf, store an element E greater than any element in the array. Figure (a) shows an example for data = {8, 20, 41, 7, 2}, h = (log2(5)) + 1 = 3, and E = 42. Then, starting from the bottom of the tree, assign the minimum of its two children values to each node, as in Figure (b), so that the smallest element emin in the tree is assigned to the root. If a leaf node is to be removed ..read more
Visit website
Assigning values to elements in an array in C (Beginner question)
Stack Overflow » C#
by VidR
48m ago
#include <cs50.h> #include <stdio.h> #include <string.h> int main(void) { int n = get_int("input number: "); int array[8]; int counter = 0; for (int i = 0; i < 8; i++) { if ((n / 2) != 0) { array[counter] = n % 2; } else if ((n / 2) == 0) { array[counter] = 0; } counter++; n = n / 2; printf("%i ", array[counter]); } printf("\n"); } Hi everyone, What I am trying to do with this code is to get an array of binary numbers for inputted decimal number ..read more
Visit website
Identifier is undefined when including the external library (windows api)
Stack Overflow » C#
by Riki
48m ago
I'm trying to include Windows SDK header files, but there are errors inside them, such as "variable 'DWORD' is not a type name", "identifier 'LPWSTR' is undefined", etc. errors I have tried adding paths of the Window kits Include directories to the include path, but it still tells that "#include errors detected. Please update your includePath." paths ..read more
Visit website
I am trying to practice converting C code to MIPS Assembly. How would I go about translating the following collatz function to MIPS?
Stack Overflow » C#
by HelpNeeded
48m ago
uint32_t collatz(uint32_t n, int d) { /* printf("%d\n", n);*/ if (n != 1) { if (n % 2) return collatz(3 * n + 1, d + 1); else { return collatz(n / 2, d + 1); } } return d; } This is the C function I am trying to rewrite in MIPS Assembly. I want to use recursion in my assembly version and I am really struggling with making the function work. I have this driver for the assembly version of the function. .data arrow: .asciiz " -> " .text main: li $sp, 0x7ffffffc # initialize $sp # PROLOGUE subu $sp, $sp, 8 # e ..read more
Visit website
What compiler options does `-O2` enable in clang? [duplicate]
Stack Overflow » C#
by KJ7LNW
48m ago
We've found that -O2 breaks a program, and we would like to find out which optimization option actually causes the problem, so we can produce a bug report. Is there an equivalent list of options that -O2 enables in Clang (for C)? I checked the docs but it just says "-O2 Moderate level of optimization which enables most optimizations." But, which optimizations ..read more
Visit website
'expected parameter declarator'. working with files in c
Stack Overflow » C#
by Rae
48m ago
More less it's my first time working with files in C, having a hard time understanding fread, fwrite and all that jazz. So I was trying to copy the header of the file saved in input folder to another file, stored with the output pointer. I keep getting an error on line 47 about & read; "expected parameter declarator". Overall whatever I do to read the compiler screams at me. And Im not sure if fseek was necessary. Any advice? fseek(input, HEADER_SIZE, SEEK_SET); int read; fread(&read, HEADER_SIZE, 1, input); fseek(input, HEADER_SIZE, SEEK_SET); for (int i = 0; i < ..read more
Visit website
Can you tell me the truth about order of evaluation VS precedence VS associativity in C? [duplicate]
Stack Overflow » C#
by Cblue X
48m ago
i read some time ago about precedence and associativity of operators in C And i thought i have it clear but read some post here on SO and i think im stuck... I read some posts/questions, here is one of them: Operator precedence versus order of evaluation I know what means order of evaluation in C, for example using functions in an expression: int x = a() + b() * c(); "The evaluation order of the 3 function calls is unspecified, i.e. the functions can be called in any order" I got this, but what about if we have this expression: int x; int a = 2; int b = 5; int c = 6; int d = 3; x = a * b ..read more
Visit website
STM32 USB to I2C IAP bridge
Stack Overflow » C#
by STeVe
48m ago
I have two STM32 boards (A and B) connected together via I2C. Board A can trigger the RESET- and the BOOT-Pins of Board B. Therefor it should be possible for Board A to use the system bootloader of board B. I can connect to Board A via USB with STMCubeProgrammer. I want Board A to translate all the USB-Bootloader-commands to I2C-Bootloader-commands, to have Board A working just as a "Bootloader-Bridge" to Board B. PC <-- USB --> Board A <-- I2C --> Board B I found the stm32-mw-openbl project, but it does: It allows all possible bootloader operations (Read, write, erase, jump...) i ..read more
Visit website
C Program keeps changing int after I add a loop
Stack Overflow » C#
by Mamushi
48m ago
I am fairly new to C so I must be doing something wrong. I have an int that keeps changing because of a loop, doesn't matter what kind of loop it is, it just changes the code to give me a completely different number due to the loop What I am expecting (which is what I get before I add the loop): first_set = 200001208 Once I add the loop: first_set = 0 Not sure what I am doing wrong since for test purposes my loop should not affect the current code at all. Here is the current code #include <cs50.h> #include <stdio.h> #include <stdlib.h> #include <string.h> string v ..read more
Visit website
Why does my program always leak memory around item 20 on the line items?
Stack Overflow » C#
by Ratdude
48m ago
I apologize for what's probably a dumb question. I'm relatively new to C. In any event, I was attempting to make a program that returns each permutation of a number. For some reason, my program always seems to fail at item 19, then leaks memory on item 20. If I run 4 or less numbers through the program, it works ok. What's causing the leak and what's the best way to prevent memory leaks going forward? Sorry if the code is also extremely messy, I'm learning. #include <stdlib.h> #include <stdio.h> #include <math.h> void switching(int *left,int *right) { int temp=0; te ..read more
Visit website

Follow Stack Overflow » C# on FeedSpot

Continue with Google
Continue with Apple
OR