c

How does a variable in C/C++ work?

How does a variable in C/C++ work? I mean, a pointer stores an address from a variable and then you have to dereference it to access the object to which it refers, so I think that a variable is a pointer that is dereferenced automatically when used... does that make any sense? BTW, I didn't find an answer to this on google... Thank yo...

Debugging a C program

#include<stdio.h> int main(int argc, char **argv) { int a,b,c; printf("enter two numbers:-"); if( scanf("%d \t %d",&a,&b) == 2 ) { c=a+b; printf("addition of numbers= %d",c); } else { printf("please enter a valid input"); getchar(); } } how to debug this code line by line in the c-debugger? please ,...

Loop in C help!

My friends tell me that a special loop exists that isn't a 'while' loop or a 'do while' loop. Does anyone know what it's called and the correct syntax for it's use? ...

Can I use C/C++ code inside my ActionScript-3 code?

I wonder if there is ways for communicate actionscript with c/c++, as well as the level of complexity.. ...

What are out-of-memory handling strategies in C programming?

One strategy that I though of myself is allocating 5 megabytes of memory (or whatever number you feel necessary) at the program startup. Then when at any point program's malloc() returns NULL, you free the 5 megabytes and call malloc() again, which will succeed and let the program continue running. What do you think about this strategy...

Why does C++ require a cast for malloc() but C doesn't?

I have always been curious about this - why do in C++ I have to cast return value from malloc but not in C? Here is the example in C++ that works: int *int_ptr = (int *)malloc(sizeof(int*)); And here is the example in C++ that doesn't work (no cast): int *int_ptr = malloc(sizeof(int*)); I heard that in C, in fact, casting an outpu...

using mount(2) function in C

I've have been desperately searching for a tutorial on how to use the mount() function properly (they are very good at hiding this knowledge). I need to use it to MNT_UPDATE " / "(/dev/disk0s2 in this case) in single user mode but I can't find an example or tutorial on how to use the function. ps. Please no "Use system()" pps. I know /...

How do you determine the optimal disk IO block size on Win32?

On Posix systems, the st_blksize member of the stat structure contains the optimal block size for IO for a given file. It looks like the Win32 implementations of stat (_stat & _stat64) do not support this field. What is the Win32 equivalent way of determining the optimal IO block size for a given file or filesystem? ...

Extract a substring in C

Hi, i am trying to extract the username from this uri field in ANSI C code on linux using gcc mail:[email protected] so i need to strip the mail: and everything after the @. Are there any built in functions in C to extract substrings ...

Defining a value of a struct in it's declaration in a header file

Please forgive me if this is a dumb question, I'm fairly new to C and couldn't find an example of this online so I assume I cant do what I want. but, hopefully someone here can point me into the right direction. so I have a headerfile that declares a struct like so typedef struct{ float *float_array1; float *float_array2; ...

Trying to write a code for finding the machine epsilon

I am trying to find out the precision level for various floating point formats in C (i.e. float, double and long double). Here is the code I'm using at the moment: #include <stdio.h> #define N 100000 int main(void) { float max = 1.0, min = 0.0, test; int i; /* Counter for the conditional loop */ ...

How to convert a MQseries reason code to string?

How do i convert/lookup a reason code of IBM Websphere MQseries to its explanation (for logging etc)? ...

Eclipse C++ include error: no such file or directory

I've loaded a C++ project into Eclipse (Europa) and I'm familiarizing myself with the CDT interface. There is one particularly annoying error message for the following line: #include "somedir/somefile.h" somedir/somefile.h: No such file or directory The include file exists in "/opt/local/project/include/somedir/somefile.h". Under P...

How is malloc() implemented internally?

Can anyone explain how malloc() works internally? I have sometimes done strace program and I see a lot of sbrk system calls, doing man sbrk talks about it being used in malloc() but not much more. I'd really like to learn how malloc() works. Thanks, Boda Cydo. ...

Is there a built-in function that comma-separates a number in C, C++, or JavaScript?

Given a number 12456789, I need to output 12,456,789 without much coding. Are there any built-in functions in either C, C++, or JavaScript I can use to do that? ...

problem with blank rows when reading from file in c

hello i am progremming in c with linux enviroment and facing a difficulty with blank rows while reading from afile. i am using strtok function for seperating the string with delimiter "," and getting segmentation error whenever the file that i am reading from contains blank lines thanks in advance ...

Bug in an addition drill program

This is an addition drill program with a bug that I can't fix up. I can't input Y/N characters in the program, please help me to fix it up. #include <conio.h> #include <stdio.h> main() { int answer, count; int ch; ch = getche(); for(count=1; count<11; count++) { printf("What is %d + %d? ", count, count); scanf("%d", &answer);...

warning: assignment discards qualifiers from pointer target type

Hi! i wrote the following code: void buildArrays(char *pLastLetter[],int length[], int size, const char str[]) { int i; int strIndex = 0; int letterCounter = 0; for (i=0; i<size; i++) { while ( (str[strIndex] != SEPERATOR) || (str[strIndex] != '\0') ) { letterCounter++; strIndex++; ...

Can't reach speeds of dd

Hi, I'm writing C code with some real-time constraints. I tested out the speed I can write to a disk with dd: dd if=/dev/zero of=/dev/sdb bs=32K count=32768 oflag=direct This writes 1GB of zeros to /dev/sdb in 32K block sizes I reach about 103 MB/s with this Now I programmatically do something similar: open("/dev/sdb",O_WRONLY|O_CR...

How to detect correct function call pairs

Hello every body I am looking a tool able to detect ordered function call pairs in a nested fashion as shown below: f() // depth 0 f() //depth 1 g() g() At each depth of call f() there must be a call of g() forming function call pair. This is particularly important in critical section entry and exit. ...