Hi all,
Recently while surfing some C++ blogs, I came across a small C teaser program in one of them.
#include<stdio.h>
int find_addr()
{
/*fill your code here*/
}
int main()
{
int i,j;
clrscr();
find_addr();
return 0;
}
The question is to find the address of variables i & j without touching the main function. I haven't been able t...
I have below lines in my code written in C on unix platform. Please let me know why I am getting core dumped in closedir() function. I could successfully opened the directory specified by path.
if (opendir(MyDir) != NULL )
{
closedir((DIR *) MyDir);
exit 0;
}
...
Hi all,
While there are good sites having interesting programming puzzles like mentioned in this SO post. But are there any specific to C/C++?
...
Possible Duplicate:
what is the difference between int i and int i?
Is there a difference between int* fooBar; and int *fooBar;? I've seen both, but are they the same thing?
...
Code:
/*
* code.c
*/
#include <stdio.h>
void printArray(int iXArray, int iSize);
int main() {
int array1[] = {7, 9, 3, 18};
int *array2[] = {array1 + 0, array1 + 1, array1 + 2, array1 + 3};
printArray(array2, 4);
return 0;
}
// This should print the values in array1
void printArray(int iXArray, int iSize) {
in...
Hi,
I am using statvfs function call on AIX. And using GCC compiler.
I would like statvfs call to resolve to statvfs64 by preprocessor.
Ex: In Solaris, using "-D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64" flags with gcc i am resolved to statvfs64.
Could you please help in getting the similar flags on AIX which resolves me to statvfs64...
Is there any way to create trigger using OCI API?
I need to perform the following actions programmatically:
CREATE OR REPLACE TRIGGER tbl_trigger BEFORE INSERT ON tbl FOR EACH ROW
WHEN (new.id IS NULL OR new.id = 0)
BEGIN
SELECT tbl_sq.nextval INTO :new.id FROM dual;
END;
/
...
I have an array that contains pointers. How can I swap two pointers - say array[1] and array[4] - correctly?
...
Is it possible to get data (such a text or numbers) from an application? For example when one's running an application the screen displays some text, images and numbers, would it be possible to code an automated procedure that would read that data (for the sake of saving it to an external file)?
...
I'm just starting out with pointers, and I'm slightly confused. I know & means the address of a variable and that * can be used in front of a pointer variable to get the value of the object that is pointed to by the pointer. But things work differently when you're working with arrays, strings or when you're calling functions with a point...
Hello,
gcc 4.4.2 c89
I have the following code.
#if defined ( __linux__ )
log_msg(stderr, "Socket failed [ %s ] [ %s ] [ %d ]\n",
strerror(errno), __func__, __LINE__);
#elif ( WIN32 )
log_msg(stderr, "Socket failed [ %s ] [ %s ] [ %d ]\n",
strerror(errno), __FUNCTION__, __LINE__);
#endif
Because I am compili...
considering a pointer to a struct
struct a_struct
{
int A;
};
Is it ok to do :
struct a_struct *ptr;
//...
if( ptr != NULL && ptr->A == 1)
{
//work with ptr struct
}
or should you Test if the pointer is valid before testing for on of its field.
if(ptr != NULL)
{
if(ptr->A == 1)
{
...
I have a command line C program for which I use the calloc() function to assign some memory for a struct which also has a struct in it with some memory assigned.
If I use the free() function to release the memory from the parent struct, will it also release the memory from the child struct?
Or should I release the memory from the child...
Hi All,
I have a large array (>10^5 entries) of 3D coordinates r=(x, y, z), where x, y and z are floats. Which is the most efficient way to search a given coordinate r' in the array and give the array index. Note that the r' may not given with the same accuracy as r; say, if the array has stored coordinate (1.5, 0.5, 0.0) and r' is give...
I would like to use scope guard in C in order to do profiling.
I would like to know how much time I spend in a function. Here is what I do:
int function() {
tic();
... do stuff ...
if (something)
{
toc();
return 0;
}
toc();
return 1;
}
I need to place a toc statement each time I exit the function. I would li...
In a game that I am writing, I use a 2D vector class which I have written to handle the speeds of the objects. This is called a large number of times every frame as there are a lot of objects on the screen, so any increase I can make in its speed will be useful.
It is pretty simple, consisting mostly of wrappers to the related math func...
Does this...
char* myString = "hello";
... have the same effect as this?
char actualString[] = "hello";
char* myString = actualString;
...
Pointers-to-pointers and references-to-pointers seem overly complicated at first, especially for newbies. What is the best and most useful reason you used one in a c/c++ project you worked on?
This can help people better understand pointers and how to use them effectively.
Edited: Included C as well as C++
...
I'm installing CGAL 3.5.1. To compile any part of it, I need CGAL/compiler_config.h, which, according to the manual, I have to generate by running cmake. Do I really need to download and run cmake, or is there a simpler way?
I'm using Visual Studio 2005 on x64 Windows. So maybe I can download a ready config for this combination, or read...
I am writing a chat program for my networking class and I have all the networking setup perfectly.
My problem is if a client is currently writing a message and he receives a message from a different client then his current input gets displayed with the received message.
For example if a client is writing a message "Hi there how are yo...