c

Explain how it works mutex

Hello, Now i'm try to learn multithreading and mutext. But i don't understand it. For example i add items to list in anotyher thread then main programm: GMutext* lock; g_mutex_lock (lock); g_list_prepend(list, "Some data"); g_mutex_unlock (lock); What happens in this case with the list? The list of added elements, as well as no acces...

Creating a test case for a buffer overflow error (C/c++)

Hello, How do you create a unit test case in c for a buffer overflow that does not cause a memory error such as a segfault? I.e. Given a simple buffer overflow, such as int function () { int exampleArray[10]; exampleArray[10] = 5; return 0; } How do you create a unit test for this code? There is clearly an error, we are ...

Implementing the clrscr() funtion to understand its working

I am trying to make the copies of the builtin functions and adding a x to their name so i can understand each functions working.While writing a function for clrscr() i am confused about how it works.Does it use 2 nested loops and print (" ") i.e space all over the screen or it prints("\n") over the screen?Or what? I tried this: #include...

debugging c programs

Programming in a sense is easy. But bugs are something which always makes more trouble. Can anyone help me with good debugging tricks and softwares in c? ...

Pass list as argument to Python C module?

I found this nice example of a Python C Module, where a single integer is passed along as the only argument. How can I instead pass a python list as argument? ...

What is the meaning of this code

I found following code in one of the frameworks we are using, if (nValue + 0.01 > nLimit) nValue = nValue - 0.01; if (((nValue+1) / (int)(nValue+1)) == 1) sprintf(szValue, "%0.0f", nValue); else sprintf(szValue, "%0.2f", nValue); what is the meaning of this code ...

what is the difference between short signed int and signed int.

I was referring a tutorial on c,I found that signed int & short signed int range are -32768 to 32767 and it's of 2 bytes, is their any difference, if not then why two kinds of declarations used. ...

ABR - Klocwork false alarms and incorrect bug disposal

Hi, Klocwork reports an error of:- "ABR – Buffer overflow, array index of 'oidsp' may be out of bounds. Array 'oidsp' of size 64 may use index value(s) -2..-1." For this line:- if (check_index_lower_legality (len,-1)) { oidsp[len-1] = specProb; } When check_index_lower_legality is:- bool check_index_lower_legality (in...

BDM elf file vs normal elf file

Whats the advantage that the BDM ELF file has over the nomral ELF file in terms of memory used? I know the following things about both: 1) BDM ELF file could be used for debugging through any debugger tools like Trace32 by plugging in JTAG. The normal ELF file also can be used for debugging purpose, provided we have the corresponding F...

Syntax error porting C code from Linux to FreeBSD

This is very puzzling to me because the code compiles without errors on a Debian 5 system but on a FreeBSD 7 I get a syntax error here on line 98 for example. int ipmi_fru_get_board_info_mfg_time(ipmi_fru_t *fru, time_t *time); Originally there was a line break between *fru, and time_t. Not sure what could cause these compiler erro...

How to compile C code in Visual Studio 2008?

I want to write a console application in C in VS 2008. What project type do I need to select and what properties I must set in order to do this? ...

Possibly a Pointer Problem in C

Hi all, I am not sure why the following code fragement is not doing what it is supposed to do. Returning the numbers 0 to 9 in the second loop would be idea. *scp is a pointer to a memory region allocated to the program. unsigned char* scp = (unsigned char*)(0x8e000000); scp_size = 10; for(i = 0; i < scp_size; i++, scp++) { *scp ...

I have to make an iPhone app that communicates with devices that support Modbus Protocol.

I have to be able to communicate wirelessly which means it would either be MODBUS TCP/IP over wifi or MODBUS RTU over bluetooth. I cannot find any modbus implementations with an objectiveC wrapper, but I can write the wrapper over a C library. How should I go forward? ...

How to write a test case for ensuring thread-safe

Hi, I wrote a thread-safe(at least the aim is that) container class in C++. I lock mutexes while accessing the member and release when finished. Now, I try to write a test case if it is really thread safe. Let's say, I have Container container and two threads Thread1 Thread2. Container container; Thread1() { //Add N items to the co...

if condition not working

My aim is to take two strings and compare there ends if both of them ends with "ing","ed" or there ends do not match.It always says that strings do not match . #include <stdio.h> #include <conio.h> #include <string.h> int ised(char str[]); int ising(char str[]); int main() { char str1[30],str2[30]; printf("Enter 1st string:\n"...

comparing strings (from other indices rather than 0)

How can one compare a string from the middle (or some other point but not the start) to another string? like i have a string str1[]="I am genius"; now if i want to find a word in it how should i compare it with the word? for example the word is am. Here is what i did.Its a bit stupid but works perfectly :D #include<stdio.h> #include<...

How to process jpg images with c/c++ most easily?

I want to iterate over each pixel color in a jpg format image, which library should I refer to to do this so that the code can be as short as possible? ...

What is the most efficient way to read a big text file backwards?

What is the most efficient way to read a big text file backwards, line by line, using Windows API functions? For example, if a file is: line 1 ... line 108777 line 108778 the output should be: line 108778 line 108777 ... line 1 I want to write a C program for this. You don't need to write a code (but if you want, that's great), I a...

listen for harware change events from the linux kernel or udev

I need to run some code on storage device mounting and unmounting. How can i listen for these events on linux? I was thinking on adding some udev rules to run some script (any know-how in this matter is appreciated). But I would much rather listen for events from the kernel in some netlink socket with my daemon (just like udev does...

gzip compatibility

Hi, I need to implement a C routine to (un)compress files in gzip format. Can anyone give me an example? I tried zlib, but it not seems compatible. Thanks. ...