c

Can looking at freed memory cause an access violation?

Can accessing (for read only) memory freed cause an access violation, and, if so, under what circumstances? ...

programs running in parallel, read/writing in C

I'm considering a set of 4 programs: (Prog1, Prog2, Prog3, Prog4) interacting with 4 files (FileA, FileB, FileC, FileD) Prog1: writes (appends) to FileA Prog2: reads File A and writes (appends) to FileB Prog3: reads File A, and writes (appends) to FileC Prog4: reads File B, and writes (appends) to FileD or Potentially Prog1, might al...

C Question: Array declared inside a function cant exceed ~8MB of memory. What am I doing wrong?

Hi, while using Eclipse on a Mac (2GB RAM) i have encountered the following problem: whenever i try to create an array which exceeds 8384896 bytes, i get segmentation faults. The following program would execute: #include <stdio.h> main() { double x[1048112]; printf("sizeof(x) = %li", sizeof(x)); } and the output would be (as...

A C style string file format conundrum

I'm very confused with this wee little problem I have. I have a non-indexed file format header. (more specifically the ID3 header) Now, this header stores a string or rather three bytes for conformation that the data is actually an ID3 tag (TAG is the string btw.) Point is, now that this TAG in the file format is not null-terminated. So ...

What happens in assembly language when you call a method/function?

If I have a program in C++/C that (language doesn't matter much, just needed to illustrate a concept): #include <iostream> void foo() { printf("in foo"); } int main() { foo(); return 0; } What happens in the assembly? I'm not actually looking for assembly code as I haven't gotten that far in it yet, but what's the ba...

Array of pointers initialization.

char **arr; arr = (char **)calloc(1,sizeof(char*)); for(i = 0; i< 16; i++) if(arr[i] = (char *)calloc(1, 2*sizeof(char)) == NULL) perror("Memory cannot be allocated to arr[i]", %d); The above code throws an error inside the for loop, when i am trying to allocate memory to arr[i]. Is anything wrong with this allocation. ...

C function syntax, parameter types declared after parameter list

I'm relatively new to C. I've come across a form of function syntax I've never seen before, where the parameter types are defined after that parameter list. Can someone explain to me how it is different than the typical C function syntax? Example: int main (argc, argv) int argc; char *argv[]; { return(0); } ...

convert rgb 2 black & white in opencv

i need to know the function that convert RGB image into black &white(binary image) & i need to know if i can save modified image after conversion on hard disk if so what's this function? ...

How to share register and bit field definitions between a device driver and the FPGA it controls

Are there any good, existing software tools available to assist in generating C header files with appropriate #defines for register offsets as well as bit definitions from VHDL? If any such tools do exist, what restrictions to they place on the VHDL and how are things that should be exported designated? So far, I've found these tools b...

Why is fwrite writing more than I tell it to?

FILE *out=fopen64("text.txt","w+"); unsigned int write; char *outbuf=new char[write]; //fill outbuf printf("%i\n",ftello64(out)); fwrite(outbuf,sizeof(char),write,out); printf("%i\n",write); printf("%i\n",ftello64(out)); output: 0 25755 25868 what is going on? write is set to 25755, and I tell fwrite to write that many bytes to a fi...

Why is this OCaml program faster than my C program?

I wrote a basic Hippity Hop program in C, Python, and OCaml. Granted, this is probably not a very good benchmark of these three languages. But the results I got were something like this: Python: .350 seconds C: .050 seconds interpreted OCaml: .040 seconds compiled OCaml: .010 The python performance doesn't really surprise me, bu...

Check Spelling program in C

hello everyone. I'm a beginner to C programming. I'm trying to learning how to code a spell checker that looks through all the words in a dictionary file, compare them with an article, print out all the words that do not exist in the dictionary file onto the console. Since I'm studying malloc in class, I've lowercased every word, removed...

Finding the function caller in C.

Hey all, I'm just wondering if it is possible to get the name of the program thats running within a function? Here's an example: Say I called: ./runProgram main() { A(); } function A() { // Possible to retrieve "runProgram" if I cannot use main's argc(argv) constants?? } ...

Combine Gyroscope and Accelerometer Data

I am building a balancing robot using the Lego Mindstorm's NXT system. I am using two sensors from HiTechnic, the first being an Accelerometer and the second being a Gyroscope. I've successfully filtered out noise from both sensors and derived angles for both in a range between -90 and 90 degrees, with 0 degrees being perfectly balanced....

Is there a C equivalent for Perl's Carp module?

In some projects I've done in C, I've liked using the following macros which work similar to Perl's warn and die subroutines: #include <stdio.h> #include <stdlib.h> #define warn(...) \ fprintf(stderr, __VA_ARGS__); \ fprintf(stderr, " at %s line %d\n", __FILE__, __LINE__) #define die(...) \ warn(__VA_ARGS__); \ exit(0x...

What is the difference between _itoa and itoa?

Visual Studio is yelling at me about using itoa()... saying to use _itoa instead? It looks to me like they are the same function... what gives? ...

C++ simple file reading problem

I have a file,named f1.txt, whose contents are 75 15 85 35 60 50 45 70 Here is my code to read each integer and print them. #include <iostream> #include <fstream> using namespace std; int main(int argc, char *argv[]) { fstream file("f1.txt", ios::in); int i; while(!file.eof()) { file >> i; cout << i << " "; } return 0;...

What windows C IDE can I use that will use gcc to compile and let me insert breakpoints just like Visual Studio would for C#?

What windows C IDE can I use that will use gcc to compile and let me insert breakpoints just like Visual Studio would for C#? I have searched Google and cannot find anything more recent that 2005. I'm just getting back into C since graduating and would like a non MS IDE that uses GCC, but that's a versatile as Visual Studio. The thoug...

What is a neat way of breaking out of many for loops at once?

Suppose I need to break out of three or four nested for loops at once at the occurence of some event inside the innermost loop. What is a neat way of doing that? what I do is use flags like this: int i, j, k; int flag1 = 0; int flag2 = 0; for (i = 0; i < 100; i++) { for (j = 0; j < 100; j++) { for (k = 0; k < 100; k++) { ...

Unusual HTTP Response in Basic C++ Socket Programming

I've got a basic HTTP client set up in C++, which works ok so far. It's for a school assignment, so there's lots more to do, but I'm having a problem. I use the recv() function in a while loop, to repeatedly add pieces of the response to my response buffer, and then output that buffer each time. The problem is, at the end of each piece ...