#pragma pack() with push and pop vs unpack

I have this sample program below #include <stdio.h> #include <stdlib.h> #pragma pack(push) #pragma pack(1) typedef struct{ char a; int b; char c; }st_a; #pragma pack(pop) typedef struct{ char a; int b; char c; }st_b; int main() { printf(“size of struct a %zd n”,sizeof(st_a)); printf(“size of struct b %zd n”,sizeof(st_b)); return 0; } Output of the above program is size of…
Read more

Read from binary file to memory in C

I want to read a binary file to allocated memory. Write in “c with classes”. Something like this: int _i; void* _buffer; char* _dat; FILE* _out; _out = fopen(_outFileName, “rb”); _buffer = calloc(SIZE, sizeof(char)); // SIZE is unknown yet, take wittingly larger number. _i = 0; while ( fread(&_dat, sizeof(char), 1, _out) ) { ((char*)_buffer)[_i] = _dat; _i++; } //…
Read more

python embedding in C : define the python script as a C string?

I would like to invoke the following python script in C : #!/usr/bin/python2.7 import parser def evaluate(text): code = parser.expr(text).compile() return eval(code) as explained in the following page https://docs.python.org/2/extending/embedding.html, i can call this script from C using the pwd(path) of the file. However, i would like to know if it’s possible to not load the script by calling python on…
Read more

Bad Substitution Error with System command in C

I have written a C program with some system command in it. I use a software called Gromacs. Here is the snippet of C code :- #include<stdio.h> #include <stdlib.h> /*I have removed unnecessary code, which works fine for me. */ int main() { float LAMBDA=0.37; for(LAMBDA=0.37 ; LAMBDA <0.55; LAMBDA +=0.02 ) { system(“g_bar -f md*.xvg -o -oi -oh”); system(“mapfile…
Read more

Is there any reason to check, if poll blocked at reading stderr?

My poll is blocked at calling point at polling STDERR fd, it never returns, I don’t know what causes it, is there any points can I check the reason? #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <errno.h> #include <poll.h> int main() { int filedes[2]; int filedes_err[2]; if (pipe(filedes) == -1) { perror(“pipe”); exit(1); } if (pipe(filedes_err) == -1) { perror(“pipe…
Read more

Doxygen enum table is generated wrong

I’m using Doxygen 1.8.10 with default generated Doxyfile to document a C sourcecode. The problem is that some enum tables are generated wrong. Here an example: /*!Enum documentation */ typedef enum tagMODULE__E_SomeFreq { RES_FREQ__0_001HZ = 0, /*!0.001 Hz – 1000 s */ RES_FREQ__0_002HZ = 1, /*!0.002 Hz – 500 s */ RES_FREQ__0_005HZ = 2, /*!0.005 Hz – 200 s */…
Read more

Should i do malloc() before using dlopen()?

Below shown is the code snippet i am using. Should I allocate space using malloc before doing dlopen? void* pvHandle = NULL; /* Dynamically loading library */ pvHandle = dlopen (“libame.so”, RTLD_LAZY | RTLD_GLOBAL); if (!pvHandle) { pszError = dlerror(); cout << “Error : ” << pszError; } Please help me clear this doubt. Thanks in Advance. Source: c#

Alphabetical sort ordering in C language

I need to Alphabetical sort ordering is defined by the ordinal values of the characters Jenny Craig,47 Billy Bob,33 Jenny Craig,29 Simon Says,234 The output would be Billy Bob (33) Jenny Craig (29) Jenny Craig (47) Simon Says (234) Here is my code is a little bit large #include <stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h> #include <stdbool.h> #include <assert.h>…
Read more