c

SIGSEGV, (seemingly) caused by printf

First and foremost, apologies for any cross-posting. Hope I'm not repeating an issue here, but I was unable to find this elsewhere (via Google and Stack Overflow). Here's the gist of the error. If I call printf, sprintf or fprintf anywhere within my code, to display a float, I get a SIGSEGV (EXC_BAD_ACCESS) error. Let me give an example...

How to copy to clipboard with X11?

Using the frameworks on OS X, I can use the following to copy a PNG to the pasteboard (in C — obviously I could use NSPasteboard with Cocoa): #include <ApplicationServices/ApplicationServices.h> int copyThatThing(void) { PasteboardRef clipboard; if (PasteboardCreate(kPasteboardClipboard, &clipboard) != noErr) { return -1; ...

How portable is the output of pcap_compile?

pcap_compile() compiles a string into a filter program in the form of a bpf_program struct. In theory I could save the compiled form of the program and supply it to pcap_setfilter() on a different network interface or even on a different machine. Will that work? Is the bpf_program form portable across different interfaces? Different pro...

Histogram generating function

i was assigned to make some changes to a C program written by someone else...i want to understand it first to work on it properly...i came upon a function that generates the histogram of ASCII values from a given long string of data. it is something like this. //load the symbols the old data for(int k = 0;k < 256;++k) { sym[k].S...

Multiplying two number arrays

Can anyone please tell me how to multiply two number arrays in C? The number arrays are basically derived from two strings containing digits. eg: 123456 and 132465. Edit: I had two string as S1 = "123456" and S2="132546". I then converted these two strings into array of ints i.e. int IS1[6] and IS2[6] so that IS1[1] = 1, IS1[2] = 2......

Guide to switch from Visual Studio to Emacs on windows?

I do not want to learn an IDE or similar software which is only made for one platform only. I want to spend my time+energy in learning something which is a timeless-truth. I want to switch to an editor-religion, which has no religion but of development and progress, it sees & treats all with equality. Yes, please provide me some guide...

Drawing text on a framebuffer in Linux from C

How can a program draw text on a frame buffer mapped in as an array? What is needed is both a means of representing the individual characters, and of drawing the characters pixel by pixel in a manner that is not too inefficient. The representation of the characters should ideally be defined solely in code, and no third party libraries wo...

Iterating over same type struct members in C

Is it possible to iterate of a C struct, where all members are of same type, using a pointer. Here's some sample code that does not compile: #include <stdio.h> #include <stdlib.h> typedef struct { int mem1 ; int mem2 ; int mem3 ; int mem4 ; } foo ; void my_func( foo* data ) { int i ; int* tmp = data ; // This ...

Generating a VERSION_STRING from major/minor/patch/build defines for use in a plist

I have a plist that is processed with a precompiled header file and in it there is the "variable" VERSION_STRING used a few times in such fields as CFBundleGetInfoString, ie the value for the key CFBundleGetInfoString is: MyProduct VERSION_STRING Copyright © 2009 MyCorp In MyHeader.h (which is the set as the Info.plist prefix header I w...

How do I parse out n-bit elements from a byte addressable array

I have a data stream that is addressable only in 8-bit bytes, I want to parse it out into 6-bit elements and store that into an array. Is there any best known methods to do this? 11110000 10101010 11001100 into an array like 111100|001010|101011|001100 (can have zero padding, just needs to be addressable this way) and the dat...

Compile C file without _cplusplus def

I'm trying to compile a C file that contains jni.h. The C code is a wrapper for my Java call to a C method. The code example that I'm trying to compile on my machine received compile errors for jstring and jclass. I believe it is due to Visual Studio cl command compile using the cplusplus option and I cannot get it to reference the co...

(c/c++) do copies of string literals share memory in TEXT section?

If I call a function like myObj.setType("fluid"); many times in a program, how many copies of the literal "fluid" are saved in memory? Can the compiler recognize that this literal is already defined and just reference it again? ...

Memory management in C

Suppose I have a structure, and a pointer to a memory location p, how do I make sure that while creating an instance 'a' of the structure, it is placed into a memory chunk starting at p? So I am passed a chunk of memory and I want to create a node at the beginning of it, so I need to make sure that the node is created at the beginning o...

Restart a career for ex-C programmer

I'm trying to re-enter the job market after a loong break - 15 years. My last full time job was programming in C with Sybase SQL backend for a corporation. Recently, I did a few websites. You know, HTML, CSS, PHP, etc. But I feel JAVA is more closely related to what I did, plus I don't really like web development - web technologies chang...

Objective-c Runtime Interface Documentation

Are the runtime interfaces(such as __objc_exec_class()) for Objective-C programs specified/documented anywhere, or they are (compiler-)implementation defined? The closest thing to a reference I have found are the GCC headers, but I'd like to know if there is some sort of reference document. ...

C pointer arithmetic for 2D arrays

// strings is a 2D array (each string is 11 bytes long) char strings[][11] = {"0123456789", "2222244444", "3333366666"}; printf("String 3 Character 2 is %c\n", strings[2][1]); How can I code this print statement using pointer arithmetic instead of the strings[2][1] ? ...

where to find xclock source code in c?

I'm looking for a while the source code for xclock in c but seems not successful to find it. Does any one know where to find it? I tried on google but no success. ...

Operation on different data types

Considering the basic data types like char, int, float, double etc..in any standard language C/C++, Java etc Is there anything like.."operating on integers are faster than operating on characters".. by operating I mean assignment, arithmetic op/ comparison etc. Are data types slower than one another? ...

is it possible to have a C/C++ GUI application in linux bare-bone server?

I am very disappointed with my school linux server when doing the homework on it. The reason is: my homework requires to make GUI application. All the tool that I have is: - ssh from my local machine to school machine - gcc/g++ in my school machine I have been thinking and tried out different solutions for a week. I still can't be ...

How to debug FUSE filesystem crash in Linux

Currently I am developing an application using FUSE filesystem module in Linux (2.6 Kernel) in C language. Due to some programming error, the application crashes after mounting the filesystem. Since I am a novice developer in Linux/C environment. Could you please let me tell me possible options to debug such programs? ...