c

Draw circle around a white area in OpenCV (C language)

Hi all, how can I draw a circle around a white space in a image file with OpenCV (C language)? image example: thanks a lot! ...

Using an ampersand in scanf()

When I compile scanf("%s", &var);, gcc sends back a warning: warning: format ‘%s’ expects type ‘char *’, but argument 2 has type ‘char (*)[20]’ however when I compile scanf("%s", var);, no warning is applied. Both pieces of code work and the book I am reading specifically says to use the ampersand, but even it doesn't in some of the e...

Optimizing for speed - 4 dimensional array lookup in C

I have a fitness function that is scoring the values on an int array based on data that lies on a 4D array. The profiler says this function is using 80% of CPU time (it needs to be called several million times). I can't seem to optimize it further (if it's even possible). Here is the function: unsigned int lookup_array[26][26][26][26]; ...

parent process, and a child process..

I am trying to write a program that The parent process will take the arguments to main() and send the characters in them one at a time to the child process through a pipe (one call to write for each character). The child process will count the characters sent to it by the parent process and print out the number of characters it received ...

How to find the physical address of a variable from user-space in Linux?

I want to find the physical address of a variable defined in a user-space process? Is there any way to do it using root privileges? ...

Compare equality of char[] in C

I have two variables: char charTime[] = "TIME"; char buf[] = "SOMETHINGELSE"; I want to check if these two are equal... using charTime == buf doesn't work. What should I use, and can someone explain why using == doesn't work? Would this action be different in C and C++? ...

use printf("text %d", number) type format to assign value to variable

I would like to use the syntax that printf uses, using the %d, %s and adding values after to assign a value to a char[]. Is this possible? e.g. Given an output of: printf("now: %d-%d-%d %d:%d:%d\n", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec); I'd like to assign that to char[] output; How can this...

Criticize my code, please

Hey, I was applying for a position, and they asked me to complete a coding problem for them. I did so and submitted it, but I later found out I was rejected from the position. Anyways, I have an eclectic programming background so I'm not sure if my code is grossly wrong or if I just didn't have the best solution out there. I would lik...

Java dropping half of UDP packets

Greetings, I have a simple client/server setup. The server is in C and the client that is querying the server is Java. My problem is that, when I send bandwidth-intensive data over the connection, such as Video frames, it drops up to half the packets. I make sure that I properly fragment the udp packets on the server side (udp has a ma...

What is the fastest way to compare two list of items?

I have two folders with approximately 10,000 files each. I'd like to write a script or program that can tell me if these folders are in sync and then tell me which files are missing from each to make them in sync. Therefore, after generating a list of files, what is the fastest algorithm to sort them for unique files? What I'm thinking...

How to (legitimately) access files after putting self into chrooted sandbox?

Changing a Linux C++ program which gives the user limited file access. Thus the program chroots itself to a sandbox with the files the user can get at. All worked well. Now, however, the program needs to access some files for its own needs (not the user's) but they are outside the sandbox. I know chroot allows access to files opened ...

Sharing memory among YACC, Lex, and C files

I have a YACC (Bison) grammar, a Lex (Flex) tokenizer, and a C program among which I need to share a struct (or really any variable). Currently, I declare the actual object in the grammar file and extern it wherever I need it (which is to say, my C source file), usually using a pointer to manipulate it. I have a shared header (and implem...

Easy C library to access MySQL

Any suggestions for a real simple C library to query a single MySQL table, nothing fancy here. Just doing a single select * from a table. Any help is appreciated. ...

ansi-c fscanf problem

hi i read the file as follows fscanf(fp,"%f %f %f\n",&*(p1+i), &*(p2+i), &*(p3+i)); my file's lines consists of three floating point numbers... the problem i have is that in the file let's say i have some floating points with let's say maximum of two digits after the dot. but when i ask c to print those values using different ...

Stack Allocation in C

Is it bad style to design your simple C programs to allocate everything, or most everything, on the stack? ...

Autocorrelation method for pitch determination: what is the input data form?

I have read a code for pitch determination using autocorrelation method. Can anybody please tell what would be the input data (passed as argument to DetectPitch()) function here: double DetectPitch(short* data) { int sampleRate = 2048; //Create sine wave double *buffer = malloc(1024*sizeof(short)); double amplitude = 0....

Are there any lint tools for C and C++ that check formatting?

I have a codebase that is touched by many people. While most people make an effort to keep the code nicely formatted (e.g. consistent indentation and use of braces), some don't, and even those that do can't always do it because we all use different editors, so settings like spaces vs. tabs are different. Is there any standard lint tool...

Testing for a closed socket

I'm trying to test for a closed socket that has been gracefully closed by the peer without incurring the latency hit of a double send to induce a SIGPIPE. One of the assumptions here is that the socket if closed was gracefully closed by the peer immediately after it's last write / send. Actual errors like a premature close are dealt wi...

Returning char* in function

I have function: char *zap(char *ar) { char pie[100] = "INSERT INTO test (nazwa, liczba) VALUES ('nowy wpis', '"; char dru[] = "' )"; strcat(pie, ar); strcat(pie, dru); return pie; } and in main there is: printf("%s", zap( argv[1] ) ); When compiling I get the warning: test.c: In function ‘zap’: test.c:17: wa...

Array's index and argc signedness

Hello, The C standard (5.1.2.2.1 Program startup) says: The function called at program startup is named main. [...] It shall be defined with a return type of int and with no parameters: int main(void) { /* ... */ } or with two parameters [...] : int main(int argc, char *argv[]) { /* ... */ } And later says: Th...