c

How to Calculate Execution Time of a Code Snippet in C++

Hi folks. I should compute execution time of a C++ code snippet in seconds. It must be working either on Windows or Unix machines I use code the following code to do this. (import before) clock_t startTime = clock(); // some code here // to compute its execution duration in runtime cout << double( clock() - startTime ) / (double)CLO...

Send a raw ethernet packet from inside a kernel module

I found out that I need to build a new sk_buff struct in the kernel module and pass it to my network device, but what I can't figure out is how to set the struct variables for a simple raw ethernet packet. This has to be easy, but i would really appreciate it, if someone could give me a sample code of how to put the sk_buff together. ...

Mac application hangs on ReadPipe from USB device

I took /Developer/Examples/IOKit/usb/USBSimple Example and modified it so that it actually transfers some data to (and hopefully soon from) the device. Here's my transferData function (commented): void transferData(IOUSBInterfaceInterface245 **intf, UInt8 inPipeRef, UInt8 outPipeRef) { IOReturn err; CFRunLoopSourceRef cfSource;...

convert values in string to float array

i have a string in C which i got from some algorithm. it has numeric values in a format like this 0.100 0.840 0.030 0.460 0.760 -0.090 and so on in need to store each of these numeric values into a float array for numeric processing. i am new to C and found string handling in C to be complex. can anyone tell me how i might implement ...

C function in VB.NET

I'm having some problems calling a C function from a DLL, and was hoping someone could help me out. The function is returning -101 which translates as a "bad parameter". The values I am passing have been returned from another, successful function call, so my current assumption is that I've built the structure incorrectly. Any help is ...

extracting substrings in C

I have the string: "foo$bar@baz" I'm looking to write a C program which will extra all three sub-strings ("foo", "bar" and "baz") and put each into it's own string. P.S. Don't worry, this is not homework. ...

audio to 8-bit text sample conversion

Hello community. I have an interesting question today. I need to convert some pokemon audio files to a list of 8-bit samples (0-255 values). I am writing an assembly routine on the MC6800 chipset that will require these sounds to be played. I plan on including an array with the 8-bit samples that the program will loop through when a fun...

pass strings by reference in C

I'm having trouble figuring out how to pass strings back through the parameters of a function. I'm new to programming, so I imagine this this probably a beginner question. Any help you could give would be most appreciated. This code seg faults, and I'm not sure why, but I'm providing my code to show what I have so far. I have made this ...

Compiler/Linking Error: Freedup

I've been trying to compile a program for hardlinking duplicate files called freedup. I did try to email the author/maintainer of the program, but it's been a long time and I haven't heard anything back from him. I'm trying to compile the program from a cygwin environment using the latest stable versions of gcc (3.4.4-999) and make (3.8...

why unsigned int 0xFFFFFFFF is equal to int -1?

perhaps it's a very stupid question but I'm having a hard time figuring this out =) in C or C++ it is said that the maximum number a size_t (an unsigned int data type) can hold is the same as casting -1 to that data type. for example see http://stackoverflow.com/questions/1420982/invalid-value-for-sizet Why?? I'm confused.. I mean, (t...

C pointers vs. Objective-C pointers

Hello! I'm coming from an Objective-C background and am trying to expand my knowledge in C. One thing has me confused, however, and that's the difference between pointers in C and Obj-C. As you can see in the examples below, things seem to behave a bit differently between both languages, and I was wondering if you could help explain w...

Floating point formatting in printf()

i have array of floats where data are stored with varying decimal points so some are 123.40000, 123.45000, 123.45600...now if i want to print these values in the string without the 0s in the end in printf() so that they are 123.4, 123.45, 123.456, without those 0s in the end. is this possible? if so how? ...

Getting included header file path in VC++

Environment: I am using MS-VC++ 6.0, I include a group of header file with some data. The header files change often, so on every change I change the path setting and re-compiler A log file is generated based on the included header files For tracking of the header file from the log file, I wish to print the header file path inside the l...

How do you keep the console from closing after the program is done in C?

Possible Duplicate: What is the Best Practice for Combating the Console Closing Issue? How do you keep the console from closing after the program is done in C? When I try to search for it I find lots of stuff about C++ and other languages, but nothing for C. Also, even for C++ there doesn't seem to be a definitive answer. So co...

Equivalent function to C's "_getch()" in Java?

Hey guys, I was messing around with C/C++ and recently found the _getch() function. I also recently got an invite to Google Wave (amazing, btw), and I wanted to emulate the ability to send messages before you actually hit the enter key. However, I don't know much (anything <.<) about networking in C/C++, while I know a decent amount abo...

Reading Superblock into a C Structure

I have a disk image which contains a standard image using fuse. The Superblock contains the following, and I have a function read_superblock(*buf) that returns the following raw data: Bytes 0-3: Magic Number (0xC0000112) 4-7: Block Size (1024) 8-11: Total file system size (in blocks) 12-15: FAT length (in blocks) 16-...

void has unknown size in Visual C++

In Visual Studio C++ version 9 (and probably other versions too), the following code: int a = sizeof(void); void const *b = static_cast<void const *>("hello world"); b += 6; Generates these errors: error C2070: 'void': illegal sizeof operand error C2036: 'const void *' : unknown size This code works under GCC, which treats sizeof(v...

How to make console screen (Turbo C editor) full screen in MS-windows vista

I creates program in c/c++ in turbo c . but i am facing problem is that i am not able to make it full screen in windows vista. please tell me how to do it? ...

Problem with formatting output c++

I am working on a binary search tree.. I am having a problem getting the nodes to left align on output. I am printing array order, pre-order,inorder,postorder... Array order format is left aligned like i want it to be.. Im basically using the same code( setw and left; in the same order) as array order as i am with preo order, and the res...

How to declare a static variable but not define it

Some times we need to pre-declare a static variable and then use it. But the variable name of this declaration may be wrong, and the compiler can not detect it, oops! Example: /* lots of codes */ static some_type some_name; /* pre-declaration */ /* but it may define "some_name" */ /* use some_name */ /* lot...