c

What is the best way to do time stamping?

Okay so I would like to do some time stamping down to uS ... mS would be okay too ... but in looking into this, I am thinking What are the BEST PRACTICES when doing time stamping? My assumptions in this case are that C/C++ code is being used. I know internal clocks have various resolutions and the like ... but I am interested in things t...

Making size_t and wchar_t portable?

To my understanding the representation of size_t and wchar_t are completely platform/compiler specific. For instance I have read that wchar_t on Linux is now usually 32bit, but on Windows it is 16bit. Is there any way that I can standardize these to a set size (int, long, etc.) in my own code, while still maintaining backwards comparabil...

Why would you use `extern void my_func();` rather than including `my_utils.h`?

I'm working on some code I didn't write and noticed that there are many extern void my_func();. My understanding is that extern in for global variables, not for functions. Is there a practical reason to declare a function as extern rather than putting it in a header file and including that? Or is this just a stylistic choice? ...

How to wrap a void* pointer into a TCL Object

I'm trying to save a void* pointer (or any pointer) into a tcl Object so I can retrieve it later. I saw SWIG convert it to a string with some encoding and later decode it. But in order to make it more efficient, I want to directly get the pointer in and out of the tcl obj. Something like a Tcl_GetPointerFromObj(). Is there anyway to do i...

Why does this C program crash?

I've mulled over this for at least an hour and I still can't find out what the problem is. #include <stdio.h> typedef struct { int Level; char* Name; } Base; Base baseStruct; int main(int argc, char *argv[]) { scanf("%s", baseStruct.Name); scanf("%d", &baseStruct.Level); printf("%s :: Level %d\n", baseStruct.Name,...

How To read/write C array stored in text file created through bin2C utility

Hi, I am creating a application, input to which is a C file having an array ( which is created with bin2C.exe ) , the code segment of the C file is:- unsigned int MyArray[] = { 0x00000001,0x00000002,0x00000005 ...}; now I need to read this array as a text file and story its value in an int array. Then I need to modify that array and ...

Linux C - Get Lock Keys Status'

How exactly does one find out the status of the lock keys on Linux (2.6.x), using C? (I have a crappy keyboard without LED's for this stuff, and I need to write an X11 app to do this) If such an app exists (and is DE agnostic - I run e16), I'd also like to hear it as well. ...

Will function pointers always initialize to NULL?

I'm using MSVC and it seems like the code below does not crash and the function pointer is initialized to NULL by the compiler. int (*operate)(int a, int b); int add(int a, int b) { return a + b; } int subtract(int a, int b) { return a - b; } int main() { if(operate) //would crash here if not NULL { cout << o...

Byte swapping a struct

Okay I hate to ask this question ... but here goes. I am writing some code in C on an x86 machine. I want to send a struct over the network and and I want to convert the struct to Network Byte Order ... I understand all the drama about packing and the the gcc packing pragmas ... what I want to know is HOW do I convert a struct (or an arr...

GtkTextView can't wrap line.

Hello I'm using Gtk on C, I need to have a GtkTextView in the middle of my window with many other widgets, I can't make the widget wrap lines. This is a very annoying behavior, anyone have any idea of what am I missing? This is the code I'm using to set it's properties: gtk_text_view_set_left_margin(GTK_TEXT_VIEW(commentsTextView),20); ...

temporary files vs malloc (in C)

I have a program that generates a variable amount of data that it has to store to use later. When should I choose to use mallod+realloc and when should I choose to use temporary files? ...

C programming vs Java programming

I'm in a C programming course, and I really enjoy it. However when I look at java code, it looks so much more... "do more work" kind of feel. Is this true? I have to take 3 semesters of java programming after this. What are your opinions on Java programming? ...

Easiest way to read this line of text into a struct?

I have a text file with data in the form: Lee AUS 2 103 2 62 TRUE Check AUS 4 48 0 23 FALSE Mills AUS 8 236 0 69 FALSE I need to each line into a struct like, however I'd like to avoid using fixed length arrays (the problem with fgets as far as I can tell): struct Data { char *sname; char *country; int *a; int *b; ...

Trimming a string of Int

In my program i want to input a string of integer e.g 2107900000. I want to get its length and then want to remove all the 0's and 1's. ...

Basic stucture of a C/C++ project (header files and cpp files)

Hello, This is a brain-dead newbie question, but here goes: What determines what files get included in a C/C++ project? My understanding is that the compiler starts with the file that has main() in it and that file will contain #include's to get various h files which contain #include's to other h files and so on until everything is in...

" escape sequence in C?

What is the escape sequence for ' " ' in C? In other words, how can i ask a while-statement to search for an occurance of ' " '? ...

Python Extension Can't Use library_dirs

WHen specifying library_dirs in a Python distutils.core.Extension I get this error when trying to build: /Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/distutils/dist.py:263: UserWarning: Unknown distribution option: 'library_dirs' warnings.warn(msg) Why is this? I am using Python 2.5 on Mac OS X. ...

C: Passing a pointer down, updated pointer can't be accessed from calling functions!

I've got a problem- I assign my pointer variable to something in a called function, but when trying to access the updated pointer in the calling functions, it doesnt show as updated, and results in a seg fault. Help! "Bottommost function": void compareStrings(char* firstFrag, char* secondFrag, int* longestCommonLength, char* suffix, ch...

GtkEntry text change signal

How can I connect a signal callback for any kind of change in a GtkEntry's buffer, including character added, deleted, text pasted or cut? I've looked in the docs for GtkWidget, GtkEntry and GtkEntryBuffer without finding this. Note: if my question was badly worded, think of the HTML DOM's change event, except that it's fired greedily a...

JSON response to C/C++ object and C/C++ objects to Java /Objective C

Hi, Is there any way to convert the JSON response to C/C++ object structure and,convert the those object (C/C++) objects back to java or Objective c. ...