Memory usage of current process in C

I need to get the memory usage of the current process in C. Can someone offer a code sample of how to do this on a Linux platform? I'm aware of the cat /proc/<your pid>/status method of getting...

Detecting 64bit compile in C

is there a C macro or some kind of way that i can check if my c program was compiled as 64bit or 32bit at compile time in C? Compiler: GCC Operating systems that i need to do the checks on:...

convert binary data into hex string for C program

I have a small binary image, that needs to be represented in a C program. The representation will be like: static const char[] = {0x1, 0x2, 0x3, 0x4...}; (so, the bytes will be represented as a...

get absolute value without using abs function nor if statement

I was thinking how to get the absolute value of an integer without using if statement nor abs(). At first I was using shift bits left (<<), trying to get negative sign out of the range, then shift...

Fast string comparison in C

I currently have this kind of loop while(1) { generate_string(&buffer); for(int i = 0; i < filelines; i++) { if(strcmp(buffer,line[i]) == 0) { /* do...

How to avoid bank conflicts when loading data from global to shared memory

A problem involves strided accesses to an unsigned char array stored in global memory of a compute capability 1.3 GPU. In order to bypass the coalescence requirements of the global memory, the...

why use malloc with structure?

Why would I use malloc when same job can be done by without malloc as below.. #include <stdio.h> #include <conio.h> struct node { int data; struct node *l; struct node *r; }; int...

Signal EOF in mac osx terminal

I am stumped by the 1.5.2 question in K&R. I googled for sometime and found out that i have to supply the EOF input after entering the characters. long nc = 0; while (getchar() != EOF) ...

Modify next Instruction in memory with gcc

I want to modify next instruction before it fetches, in best answer of This post in foo function, *p points to the next instruction in main function. I want to modify content of where *p points...

How to get a file list from a directory inside the linux kernel?

I just saw there is a ROOT/directory before any rootfs (whether from initrd or form a disk) I already know it do contains /rootand/devwith a mounted devtmpfs (if CONFIG_DEVTMPFS_MOUNTis...

Function list on main page with doxygen

I'm sure this has already been asked somewhere but I can't seem to find it, so here it goes. I am creating a program in C and using Doxygen to generate documentation. I am quite satisfied with the...

Argument of type uint64_t is incompatible with parameter of type void*

I have a function foo(void* pBuf). I need to pass it a 64 bit address but I can't seem to get the right typecast when I'm passing by value. Example: foo(address). Where- uint64_t...

How to load texture Opengl?

I found a useful post at this site, where some code is used to load a BMP This code should load the header, read out infos, go further, read data, generate texture and bin it. But it doesnt work....

How to compile and run in one line on linux terminal?

Everytime I compile and run c file, I have to type: gcc filename.c a.out I don't want to do this in two lines, How to compile and run in one line on linux terminal?

How to make sense of modulo in c

i am not understanding this modulo in c languge. For example: #include <stdio.h> #include<math.h> int main() { int my_input[] = {23, 22, 21, 20, 19, 18}; int n, mod; int nbr_items =...

How does the compiler know the prototype of printf( ) in this code?

In the following code, #include<conio.h> clrscr(); gotoxy(10, 20); ch= getch(a); we can see that the library functions have been called without defining their prototype, the three library...

Strlwr function - getting an error in xcode 9.2

I'm trying to convert a string from upper case to lower case to check if it is a palindrome, however I keep getting the error: "function declaration is not a prototype" I already added #include...

CS50 Recovering jpg images from card.raw

I have some issues regarding the CS50 Pset4 Recovery of jpg files problem. My code is able to compile, however only 2 jpg files were created even though it should have created 50 jpg files. I...

Makefile to compile all .c files without needing to specify them

I'm trying to create a Makefile that causes all .c files to be compiled without the need to add filenames line per line inside the Makefile. I think this is fairly similar to...

Why should I always enable compiler warnings?

I often hear that when compiling C and C++ programs I should "always enable compiler warnings". Why is this necessary? How do I do that? Sometimes I also hear that I should "treat warnings as...

Return with no expression

How does return work exactly? I found the below code and am confused how it works. You can see in the if (n==1) statement the return has no value next to it. void bubbleSort(int arr[], int n) { ...

How do I print ordinal indicators in a C program? Can't print numbers with 'st', 'nd', 'rd'. (Beginner)

#include <stdio.h> main() { int i, num, sum=0; //declaration printf("How many numbers do you want to calculate average of?\n"); scanf("%d", &num); //how many numbers are to be...

How to convert Unicode char to "Unicode HEX Position" in Arduino or C

How to convert Unicode char to "Unicode HEX Position" in Arduino or C i will share a picture here : for example in JavaScript you can do that with charCodeAt(); ! this function will return...

Is there any difference between int main(int argc, char* argv[]) and int main(int argc, char** argv)

Is there any difference between int main(int argc, char* argv[]) and int main(int argc, char** argv) I don't see any difference. And, which is better to use?

CodeSignal problem. I want to complete the code

I have the following problem. The function printMatrix Receive an matrix for example: matrix: [[0,1,1,2], [0,5,0,0], [2,0,3,3]] The code that I must use is the following: // Definition for...

How to handle char16_t or char32_t with printf and scanf in C?

If I write: char a = 'A'; printf("%x %c", a, a); it will produce the output "41 A". Similary when I write char32_t c = U'🍌'; printf("%x %c", c, c); //even tried %lc and %llc it will produce...

Reserving a large virtual memory space for a dynamic array and mapping core memory as needed

I need a large dynamic array. I don't know the maximum size it can reach, but I can set a large upper bound, like 1 gigabyte. The dynamic array implementations I know, when they reach their max...

CS50 pset4 filter blur function

I wrote a code for the blur function, but it returns a wrong output for reason which is not known for me (it just looks fine for me), here is an example (always same): :( blur correctly filters...

Is there a mistake in the C standard description of pointer declarators?

C 2018 6.7.6.1 1 says: If, in the declaration “T D1”, D1 has the form     * type-qualifier-listopt D and the type specified for ident in the declaration “T D”...

Does idiomatic initialization of a dynamic array invoke Undefined Behavior?

This question may be a bit controversial. I have a following code at block scope: int *a = malloc(3 * sizeof(int)); if (!a) { ... error handling ... } a[0] = 0; a[1] = 1; a[2] = 2; I argue that...