Is it evil to serialize struct objects using memcpy?
In one of my projects I am doing the following: I memcpy a struct object, base64 encode it, and write it to file. I do the inverse when parsing the data. It seems to work OK, but in certain situations (for example when using the WINDOWPLACEMENT for the HWND of Windows Media Player) i...
I need a way to get complete hard drive info on OS X, meaning all hard drive model names, SATA/ATA controllers, volumes, disk identifiers, etc. I checked out diskutil, but it doesn't contain SATA controller info, system_profiler has all the information I need but its XML output is not necessarily organized as well as I'd like. Is there a...
I've been looking at docs but I can't seem to understand very clearly, them do you guys know of anything that would be good at teaching it.
Say I had a program,
int main() {
return 3;
}
How do I call cprogram.exe and get the return value (not neccesarily an int, structs too). I don't have a specific project that I'm working on, ju...
I'm working a MS paint-like application on OpenGL using Bresenham's midpoint algorithm as homework. So far I can draw lines and ellipses. I lose them all when resizing the window. How can I keep them drawn?
Full code:
#include "GL/glut.h"
#include <stdio.h>
#include <math.h>
int i;
//int mainWindow, subWindow;
int X1, Y1, X2, Y2;
in...
Hi
I am about to create a function for a program, this is part of a program and is meant to be a bitmap that holds controls of which memory address is free for use (this has nothing to do with this function to do). The bitmap is bit[64] which holds 8 x 64 bits, the function under is taking a parameter number that is the number of data b...
My argument is like this
./a.out -i file1 file2 file3
How can I utilize getopt() to get 3 (or more ) input files?
I'm doing something like this:
while ((opt = getopt(argc, argv, "i:xyz.."))!= -1){
case 'i':
input = optarg;
break;
...
}
I get jusst the file1, how to get file2, file 3 ??
Thanks in advance
...
hi..
I have developed (TCP) server to listen to a client and interact with it. Now I'm trying to adapt that server code to listen to mulitple clients. I am wanting to use select, but I'm getting confused with some of the examples and explainations I've found.
I have been reading: http://support.sas.com/documentation/onlinedoc/sasc/doc7...
I am trying to print the value pointed to by an address but the problem is I need to dereference this pointer based on the size that is passed to me. So something of this sort:
void print(Address addr, Int size) {
...
}
I am a little confused on how to achieve this. Can someone point me in the right direction?
EDIT:
Ok so I'm thinkin...
Hi,
Is there a POSIX function equivalent to _malloc_r and _free_r from CYGWIN? Is there a POSIX reentrant library?
Please advice.
Many thanks.
...
I am writing a program with a few critical sections. The thing is I need to check the value of a mutex in an if statement.
I would like to do something like this:
if pthread_mutex(&mutex) == 0 // locked
// Do something
else if pthread_mutex(&mutex) == 1 // unlocked
// Do something else
Is this possible?
...
I'm using C (gcc) and ncurses, to make a program that will be monitoring data coming from the serial port. The program has a big while, where it reads the data coming from the port and at the same time, it prints that info in the screen...
But the problem is here:
How can it read input from my keyboard, (since getch() freezes the progr...
#include <stdio.h>
#define SIZE 5
void func(int*);
int main(void)
{
int i, arr[SIZE];
for(i=0; i<SIZE; i++)
{
printf("Enter the element arr[%d]: ", i);
scanf("%d", &arr[i]);
}//End of for loop
func(arr);
printf("The modified array is : ");
for(i=0; i<SIZE; i++)
printf("%d ", arr[i]);
re...
I saw this example when I was trying to figure out how to pass pointers to dynamically allocated 2d arrays to functions:
void zeroit(int **array, int nrows, int ncolumns)
{
int i, j;
for(i = 0; i < nrows; i++)
{
for(j = 0; j < ncolumns; j++)
array[i][j] = 0;
}
}
I tried it and it works, but I don't understand how. How doe...
In C89 there're 15 header files:
<assert.h> <locale.h> <stddef.h> <ctype.h> <math.h>
<stdio.h> <errno.h> <setjmp.h> <stdlib.h> <float.h>
<signal.h> <string.h> <limits.h> <stdarg.h> <time.h>
What about the c++ standard?
...
Hello All,
Is it possible to use TinyXML over a byte stream instead of a file?
Consider this code snippet:
TiXmlDocument doc("abc.xml");
if (!doc.LoadFile())
return;
TiXmlHandle hDoc(&doc);
The above code snippet takes a file as input. How can I modify the code so that it accepts a byte stream? A sample code snippet would be great!...
What is the correct way to work out how many bytes an int is? and how do I write an int to a file descriptor?
Here is a mock code sample which might make clear what I am trying to achieve:
char *message = "test message";
int length = strlen(message);
int fd = open(file, O_CREAT|O_RDWR);
write(fd, length??, ??); // <--- what goes here
w...
I'm programming a microcontroller in C and as part of it want to display certain letters on a 7 segment display. Each letter has a corresponding number that makes the 7 segment display show the letter. There's no real pattern to it cause the number is just made by adding up the bits on the 7 segment display that are needed to show the le...
Hi,
I am looking some info about reentrancy, then I encountered about signal and thread. What is the difference between the two?
Please advice.
Many thanks.
...
Hi
I have a method in my process that should be run only if the process is not in background.
How can I dynamically test if the current process is in background ?
Thanks
...
Seems all compilers can deal with both c and c++,like gcc ,msvc...
Is it because these 2 languages are exactly very much alike?
...