I'm attempting to insert some integers into a Postgres table with the following somewhat simple code.
#include <libpq-fe.h>
#include <stdio.h>
#include <stdint.h>
int main() {
int64_t i = 0;
PGconn * connection = PQconnectdb( "dbname='babyfood'" );
if( !connection || PQstatus( connection ) != CONNECTION_OK )
return 1;
print...
MenuetOS is an example of an OS written entirely in Assembly. Is there any advantage to writing it in Assembly instead of a low-level programming language such as C?
...
I'm primarily a c#/.NET programmer, but the hobby project that I am about to take on will involve coding in c.
I know that there is a ton of c code out there, but its very hard to separate a well structured c project from a badly structured project if you did not "grow up" with the language. Can anyone point me toward a newer, non triv...
I just started working with C & Xcode and I've run into a little difficulty.
All I want to do is read a file from the command line and see the output in the terminal.
I think my problem lies with the path to the file that I want to read in. I'm using a Mac and the file is on my desktop, so the path should be Users/myName/Desktop/words.t...
I'm trying to get a list of all users and all groups on Mac OS X 10.5+. How can I do this?
For example, the list of all users on my machine should return:
_amavisd, _appowner, _appserver, _ard, _atsserver, _calendar, _carddav, _clamav, _coreaudiod, _cvmsroot, _cvs, _cyrus, _devdocs, _dovecot, _eppc, _installer, _jabber, _lda, _locatio...
This is what I offered at an interview today.
int is_little_endian(void)
{
union {
long l;
char c;
} u;
u.l = 1;
return u.c == 1;
}
My interviewer insisted that c and l are not guaranteed to begin at the same address and therefore, the union should be changed to say char c[sizeof(long)] and the return...
In RTOses like vxworks whenever we create a task the stacksize is specified . Can we write a routine in C which checks if the stack is overflowing or not for the task ?
...
Most high-level languages (Python, Ruby, even Java) use pass-by reference. Obviously, we don't have references in C, but we can imitate them using pointers. There are a few benefits to doing this. For example:
int findChar(char ch, char* in)
{
int i = 0;
for(i = 0; in[i] != '\0'; i++)
if(in[i] == ch)
retur...
My question specifically is in regards to arrays, not objects.
There a few questions on SO about malloc()/free() versus new/delete, but all of them focus on the differences in how they are used. I understand how they are used, but I don't understand what underlying differences cause the differences in usage.
I often hear C programmers...
Let's say I have a pointer allocated to hold 4096 bytes. How would one deallocate the last 1024 bytes in C? What about in C++? What if, instead, I wanted to deallocate the first 1024 bytes, and keep the rest (in both languages)? What about deallocating from the middle (it seems to me that this would require splitting it into two poin...
basename(3) and dirname(3) can split an absolute path into its respective components.
Short of using snprintf(3), is there a natural posix-compliant library call that does the inverse - takes a directory and a filename and concatenates them?
Manually concatenation works fine for me, but can get a little tedious at times.
...
Hello! I have some project consisting of a couple of DLL's which have been compiled with MinGW with debug information, and another project with EXE target which uses these DLLs (compiled with MinGW too).
The problem is, I need to put breakpoints on functions inside those DLLs, but GDB, although sets them, just silently ignores them at ...
I know we should free any variable allocated with malloc, but what if I return it in a function? Something like this:
char *somefunction(int somearg){
char *str;
str=(char *)malloc(sizeof(char *));
//some code
return str;
}
Should I free str? How could I do that?
...
I'm trying to read a process memory using the following code:
void readdata(HANDLE phandle, LPCVOID paddress, SIZE_T datasize)
{
char *buff;
SIZE_T dataread;
BOOL b = FALSE;
buff = (char *) malloc (datasize);
b = ReadProcessMemory(phandle, paddress, (LPVOID)buff, datasize, &dataread);
if(!b)
{
printf(...
How do I implement no-op macro in C++?
#include <iostream>
#ifdef NOOP
#define conditional_noop(x) what goes here?
#else
#define conditional_noop(x) std::cout << (x)
#endif
int main() {
conditional_noop(123);
}
I want this to do nothing when NOOP is defined and print "123", when NOOP is...
Please explain the following paragraph.
"The next question is whether we can assign a certain value to a variable without losing precision. It is not sufficient if we just check for overflow during the addition or subtraction, because someone might add 1 to -5 and assign the result to an unsigned int. Then the actual addition does not o...
I've heard so much about buffer overflows and believe I understand the problem but I still don't see an example of say
char buffer[16];
//code that will over write that buffer and launch notepad.exe
...
I am writing a function to process an incoming 32-bit buffer, representing changing data when it is compared to an corresponding stored 32-bit buffer. The position of the changing bit represents a number (i.e. a value of 8 means bit 3) that needs to be processed, along with whether the change is 0->1, or 1->0. Here is the current impleme...
I've just got my hands on a Stackoverflow data dump, and I'm disappointed to see that the Body field of the posts is in HTML rather than Markdown. I suspect there's Markdown in the original database because that's what I see if I try to edit an answer.
I want to recover Markdown from a large set of answers. I will be processing hundre...
Hi,
Using the instrument-functions flag in gcc, you can instrument the code to execute functions before and after each execution of a function.
These functions are __cyg_profile_func_enter and __cyg_profile_func_exit with two parameters, the address of a current function; the second parameter for enter is the address of the call site an...