c

Segmentation fault in equating a char pointer value to some char

Possible Duplicate: Why is this C code causing a segmentation fault? char* string = "abcd"; now when i try to change some character of this string i get segmentation fault *string = 'p'; or string[0] = 'p'; string[0] = 52; Can someone please explain me the reason that why is it happening. Thanks Alok.Kr. ...

Weird behavior of right shift operator

Hi, I recently faced a strange behavior using the right-shift operator. The following program: #include <cstdio> #include <cstdlib> #include <iostream> #include <stdint.h> int foo(int a, int b) { return a >> b; } int bar(uint64_t a, int b) { return a >> b; } int main(int argc, char** argv) { std::cout << "foo(1, 32): " <<...

Pthread lost signals / slow conditions?

Hello, I'm writing a simple threadpool for some small jobs (100 to 700 microseconds). I'm working only with two threads (because there are only two jobs and the processor has only two cores). My problem is that most of the time both jobs are executed by the same thread. The problem does not occur with bigger jobs (some milliseconds). T...

Throw (or correspondingly) on NULL function argument versus letting it all blow up?

In previous large-scale applications requiring high robustness and long up-times, I've always been for validating a pointer function argument when it was documented as "must never be NULL". I'd then throw an std::invalid_argument exception, or similar, if the argument actually was NULL in C++ and return an error code in C. However, I'm ...

rrd file maping problem

i have already writing c program, that read and write in rrd file with function rrd_update(...). but after 3 week, my process is dead, i have looked log file and found that output : Error: RRD_UPDATE command: mmaping file '/..../0668f1eb34db5551e61488b05944028c.rrd': Cannot allocate memory ...

md5sum of file in Linux C

I want to find md5sum of a file in Linux C, Is there any API where I can send file name to get md5sum of that file. ...

how to calculate total no of iteration of innermost loop of nested for loop? is there any formula?

for example int count=0 for(int i=0;i<12;i++) for(int j=i+1;j<10;j++) for(int k=j+1;k<8;k++) count++; System.out.println("count = "+count); or for(int i=0;i<I;i++) for(int j=i+1;j<J;j++) for(int k=j+1;k<K;k++) : : : for(int z=y+1;z,<Z;z,++,) count++; w...

file descriptor polling

Hi, I have created a following program in which I wish to poll on the file descriptor of the file that I am opening in the program. #define FILE "help" int main() { int ret1; struct pollfd fds[1]; ret1 = open(FILE, O_CREAT); fds[0].fd = ret1; fds[0].events = POLLIN; while(1) ...

Change direction of a moving object....(pure physic question)

Hi, This is a pure physic question but i don't know why it doesn't work....i have a moving object.i get the value of vcos(theta) and vsin(theta)...from this i calculate the velocity and angle of motion.....also i know another point (x,y) and want to direct the object to this point.I think i need to apply a certain force(force must hav...

WinAPI - Problem to append text to an editbox

Hi, I created a simple window with a multiline Edit Control: Edit = CreateWindowEx(WS_EX_CLIENTEDGE, TEXT("EDIT"), NULL, WS_CHILD | WS_VISIBLE | ES_MULTILINE, 20, 200, 200, 200, hWnd, (HMENU)EDIT, GetModuleHandle(NULL), NULL); If I set text using a WM_SETTEXT message, I don't...

gcc wont compile and run MySQL C libraries

#include <my_global.h> #include <mysql.h> int main(int argc, char **argv) { printf("MySQL client version: %s\n", mysql_get_client_info()); } ~$ gcc -o mysql-test MySQL-Test.c im trying to execute this test program from terminal but get the following error message: /tmp/cceEmI0I.o: In function main': MySQL-Test.c:(.text+0xa): ...

How to retrieve the HD vendor/serial using Windows API

I'm talking about the physical disk drive, not volume/partition/logical drive. So that usually-suggested GetVolumeInformation function is not applicable in my case. To be exact: I'm working directly with the disk which has not been partitioned yet. I open a handle to it via CreateFile function: hDisk = CreateFile( _T("\\\\.\\PHYSIC...

Library for playing Audio files in Linux C

I want to play audio files using my C programs in Linux. Can any one suggest me good development libraries for playing audio files in Linux? ...

c, c++ most basic double quotes

char* a="HELLO WORLD"; IF ADDRESS of 'H' is 0x01 then the printf with %s prints to D but if the same code is written with manual printing routine while(*a!=NULL) {printf("%c",n[a]);n++;} this prints a few more characters.. but printf("%s",a); prints it perfectly. while(*a++) printf("%c", *(a-1)); or for(;*a++;)printf("%c", *(...

How to swap bit position value 12 34 56 78?

Ex: Like binary value 1010 then after swap pair bit position value 0101 ...

A question on c program language

i want print a statement 5 times without using any loop n should be in a line ...

"scicosim: error. Type 0 not yet supported for outtb." how to solve this problem?

I'm having an incomprehensible problem in Scicoslab in the last few days. I've been writing some communication blocks (to send data to an external application) for scicos in C and then wrap them with it's own code. The problem is that, even if the code is working (I've checked every output possible), scicos gives me this error message: s...

Strange behavior (SEGFAULT) of a C program using stdargs (va_start)

Hi folks, I wrote a variadic C function which mission is to allocate the needed memory for a buffer, and then sprintf the args given to this function in that buffer. But I'm seeing a strange behavior with it. It works only once. If I have two calls for this function it segfaults. #include <stdio.h> #include <string.h> #include <stdlib....

Why Bitshift operators???

I dont understand when and why you would use bitshift operators for microchip programming: for example... SWITCH_DDR &= ~SWITCH_BIT; SWITCH_PORT |= SWITCH_BIT; Why use these operators? Or... void SerialInit(void) { UBRRH = ((XTAL / (8 * 250000)) - 1)>>8; // 250kbps at 16Mhz UBRRL = (XTAL / (8 * 250000)) - 1; UCSRA = (1...

Linked list of timers in C

Hello people, I'm supposed to write a program with two functions: One function is responsible for building a data structure populated by a list of functions within a run (you get a function pointer) its run time (a few seconds after starting a given program running). You should know to operate the function, adding the data structure o...