I don't understand fully how lists in c work

So I’m trying to add an element to the beginning of a list. The function prepend_list is at line 27. I’m trying to make it in two different ways, one returns a list back and one is a void function. #include "base.h" #include "string.h" typedef struct Node Node; struct Node{ int value; Node* next; };… Read More I don't understand fully how lists in c work

Trying to convert a message in its bits counterparts

I have the code below which should convert an user message input to its bits counterpart. For example "Hi!" should be converted to 01001000 01001001 00100001 #include <stdio.h> #include <stdlib.h> #include <cs50.h> #include <ctype.h> #include <string.h> int printbulbs(int ascii_input); int main(void) { char *Mesaj = get_string("Message: "); int size = strlen(Mesaj); int *ascii_conversion = malloc(size… Read More Trying to convert a message in its bits counterparts

Program does not find highest number in array as intended

This program is supposed to return the highest number in the array "array". But it only returns the highest number between the first and second numbers. Why? #include <stdio.h> #include <stdlib.h> int HighestNumber(int* array) { int highest = INT_MIN; for(size_t x = 0; x < sizeof(array) / sizeof(array[0]); x++) if(array[x] > highest) highest = array[x];… Read More Program does not find highest number in array as intended

error: lvalue required as increment operand without an error line

I’ve seen a similar post on StackOverflow about this error code, but theirs seemed to have an error code line, and they were also attempting something slightly different in their function. I’m trying to count the number of a specified character in a string (inputting p and apple would return 2, for example). At some… Read More error: lvalue required as increment operand without an error line

Why is this function not returning a char data type?

//Prime function #include <stdio.h> #include <math.h> char Premier(int N){ int i; char notpremier="Nombre n’est pas premier"; //Number is prime char premier="Nombre est premier"; //Number isn’t prime for(i=2;i<=sqrt(N);i++){ if(N % i==0){ return notpremier; } else{ return premier; } } } int main() { printf("%c",Premier(10)); return 0; } However, when I choose to return an int data… Read More Why is this function not returning a char data type?

C Return Value from Function Best Practice

What option is recommended in C to return an array from a function? Option 1: void function_a(int *return_array){ return_array[0] = 1; return_array[1] = 0; } Option 2: int* function_b(){ int return_array[2]; return_array[0] = 1; return_array[1] = 0; return return_array; } >Solution : This function int* function_b(){ int return_array[2]; return_array[0] = 1; return_array[1] = 0; return… Read More C Return Value from Function Best Practice