c

can I access a struct inside of a struct without using the dot operator?

I have 2 structures that have 90% of their fields the same. I want to group those fields in a structure but I do not want to use the dot operator to access them. The reason is I already coded with the first structure and have just created the second one. before: typedef struct{ int a; int b; int c; object1 name; } str1; ...

Cannot place breakpoint in gdb in emacs

I'm trying to debug a small program I've written in C. I open up the file in emacs, M-x gdb, give the program filename (a.out). When i switch to the source file in the emacs pane, and try to place a breakpoint in the main function, I get the message "No default breakpoint address now." and the breakpoint doesn't place, so I can't debug t...

How do I prevent a char pointer buffer overflow?

i.e. - int function(char* txt) { sprintf(txt, "select * from %s;", table); //How do I set last char in buffer to NULL here? } so if the text in table some how was 500 chars long and txt in the main was only defined as 100.... thanks. ...

Using SciTE to compile/build/run a C program

I'm trying to use SciTE to compile/build/run a C program that I have contructed. However, everytime I tell it to go, I get the error, "The system cannot find the file specified.". I don't know how to fix it or what could be the problem? Does anyone have any pointers? ...

Why unsigned int contained negative number

Hi All, I am new to C, What I know about unsigned numerics (unsigned short, int and longs), that It contains positive numbers only, but the following simple program successfully assigned a negative number to an unsigned int: 1 /* 2 * ===================================================================================== 3 * 4 *...

Easily measure elapsed time

I am trying to use time() to measure various points of my program. What I don't understand is why the values in the before and after are the same? I understand this is not the best way to profile my program, I just want to see how long something take. printf("**MyProgram::before time= %ld\n", time(NULL)); doSomthing(); doSomthingLo...

Why is this C program giving a 'wrong' output?

Why is this C program giving a 'wrong' output? #include<stdio.h> void main() { float f = 12345.054321; printf("%f", f); getch(); } Output: 12345.054688 But the output should be, 12345.054321. I am using VC++ in VS2008. ...

Storing a NTFS Security Descriptor in C

My goal is to store a NTFS Security Descriptor in its identical native state. The purpose is to restore it on-demand. I managed to write the code for that purpose, I was wondering if anybody mind to validate a sample of it? (The for loop represents the way I store the native descriptor) This sample only contains the flag for "OWNER", b...

Algorithm for voice comparison

Given two recorded voices in digital format, is there an algorithm to compare the two and return a coefficient of similarity? ...

JNA unsigned integer by reference gives strange results

I'm currently trying to access a C API using JNA. But I have a problem with unsigned integer parameters that are being passed by reference. So here is the C function in question: int EE_DataGetNumberOfSample(DataHandle hData, unsigned int* nSampleOut); In Java I have: public int EE_DataGetNumberOfSample(Pointer hData, ByReference nS...

C Different answers for a variable when running 'Debug' and 'Start without debug'

I keep getting this weird output from my code everytime I use the 'start without degugging' (ctrl-F5) as opposed to normal 'debug' (F5). When I try to find the following value of norm_differnece in debug (pressing F5) mode, it gives me the correct answer for norm_difference normdifference = 1.000000 but in 'start without debugging' (...

Hi, i have a C programming question. I want to know the difference between the two and where one is useful over other?

Hi, I have a C programming question. I want to know the difference between the two and where one is useful over other? Suppose I have a struct called employee as below: struct emp{ char first_name[10]; char last_name[10]; char key[10]; }; Now, I want to store the table of employee records, then which method should I use: ...

How can I know the IP address of a remote host by using UDP broadcast message?

Hi All, I am developing an embedded system and very new to this TCP\IP. My problem is that once I installed my board in a local network and this board will acquire its IP address dynamically, it has to communicate with a client application running on one of the PC(other than DHCP server) in the network. To communicate with this new boar...

C embedded automatic unit test generation

Hello all, Is there any SW to generate unit tests in C and embedded applications? The reason I am asking is that my boss told me he heard from someone that "You need a tool to analyze the code and create 80% of all relevant testcases automatically, the remaining 20% you use all your time and focus on", else it would take "too much time"...

Basic shared memory program in C

Hi, I want to make a basic chat application in C using Shared memory. I am working in Linux. The application consist in writing the client and the server can read, and if the server write the client can read the message. I tried to do this, but I can't achieve the communication between client and server. The code is the following: Ser...

Embedding Python and adding C functions to the interpreter

I'm currently writing an applications that embedds the python interpreter. The idea is to have the program call user specified scripts on certain events in the program. I managed this part but now I want the scripts to be able to call functions in my program. Here's my code so far: #include "python.h" static PyObject* myTest(PyObject...

Need help in translating code from C to Java.

From this article. Here's the code: float InvSqrt(float x){ // line 0 float xhalf = 0.5f * x; int i = *(int*)&x; // store floating-point bits in integer i = 0x5f3759d5 - (i >> 1); // initial guess for Newton's method x = *(float*)&i; // convert new bits into float x = x*(1.5f - xhalf*x*x); // One round of Newton's method ...

Segmentation fault with queue in C

I am getting a segmentation fault with the following code after adding structs to my queue. The segmentation fault occurs when the MAX_QUEUE is set high but when I set it low (100 or 200), the error doesn't occur. It has been a while since I last programmed in C, so any help is appreciated. #include <stdio.h> #include <stdlib.h> #incl...

send socket c ctrl+c behavior

I'm witting an application based on a server and various client but I'm having a problem with the send command. Whenever I do ctrl+c on the client side the send operation kills the thread which is in and the process running (in order to have multiple clients I set a thread to which one). If the client ends (doing the close socket) prope...

Compile a shared library statically

I've got a shared library with some homemade functions, which I compile into my other programs, but I have to link the end program with all the libraries I have used to compile the static library. Here is an example: I have function foo in the library which requires a function from another library libbar.so. In my main program to use f...