It is always better for contants such as PI to #define them or declare them const so the compiler can optimize and it becomes less error prone. I was wondering however, how are literal numbers in statements treated? Ex:
float x;
const int y = 60;
x = y / 3.0f;
In this example how would 3.0f be treated? Would it inherit the optimizatio...
I some how got it working but I still have a problem with the sorting and making pairs so that I can determine the winner.
Pair them(Pairs are cards with the same value.)e.g Ace of Hearts & Ace of Spades make a pair.
I then count those pairs. hand with highest pairs wins.
This was what I was trying for the pairing but.. am still relly...
is there any method to remove the duplicate elements in an array in place in C/C++ in 0(n)?
Suppose elements are a[5]={1,2,2,3,4}
then resulting array should contain {1,2,3,4}
the solution can be achieved using two for loops but that would involve O(n^2) i believe.
...
Hi,
I have a simple question in understanding the pointers and struct definitions in the linked list code.
1)
typedef struct node
{
struct node* next;
int val;
}node;
here if I use two "node" when i initialize node *head; which node I am referring to?
2) Here I use an int val in the struct. If I use a void* instead of int is th...
How do I call the lstat system call in linux/c, not the lstat wrapper around it (lstat(3))? There is no SYS_lstat for syscall(SYS_lstat...
...
I want to use the SIGNAL SIGSUR1 to communicate between two processes, but I get the compiler error:
error: ‘SIGSUR1’ was not declared in this scope .
What's the fix?
#include <stdio.h>
#include <unistd.h>
#include <sys/time.h>
#include <stdlib.h>
#include <fcntl.h>
#include <signal.h>
#include <sys/types.h>
void cursor(...
turtle(int fd,int sec1,int turtle_speed){
signal(SIGUSR1,handle(fd,turtle_speed));
struct timeval b;
int flag=1,turtle_current_pos,turtle_previous_pos=0,sec2;
turtle_current_pos=0;
while(turtle_current_pos<100){
sleep(2);
gettimeofday(&b,NULL);
sec2=b.tv_sec;
//printf("%d\...
#include <stdio.h>
//#include <conio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/types.h>
int t_array[100];
int h_array[100];
int c,h_comp=0,race_length=0,o=0,i=0,Ti=0;
void cursor(int y)
{
int i;
printf("%c[%d;%df",0x1B,y,o);
}
void turtle_fun()
{
int Ti=0;
while(h_comp!=1&&Ti<=race_length-1)...
I'm working on OS X Snow Leopard and need to programmatically generate an MD5crypt() password to match with passwords generated on Ubuntu 8.04 (crypt() on that platform uses MD5 if the salt starts with $1$ because it uses the crypt() found in glibc2 which has that functionality).
There is a md5crypt routine on OS X, but unfortunately, i...
Hi.
For a test I'd like to load two instances of a shared library from an application. The code in the library provides an API but it does not allow me to initialize two (or more) instances of the library because some of the functions rely on static variables..
I'm currently writing unit-tests for this lib, and I'd like to have two ins...
Hi,
I am struggling to continuously read contents of stdout which is redirected to file. please help me to resolve issue.
My problem in detail is that i have two thread in first thread , i have to execute a c file which is continously writing output to stdout(i.e writing hello world in infinite loop) and in second thread i have to re...
Hi,
What does the address in a pointer refer to, real address location in main memory or virtual address. Can it be configured.
And if it refers to virtual address , does Memory manager needs to convert this address to real address everytime it is accessed
...
I'm building simple http status checker in C. I've got the network part done, but I'm having trouble with string manipulation. Here how it works:
$ ./client http://domain.com/path.html#anchor
200
This utility simply outputs the status of given page on the command line. I need to parse the given string into hostname and request path. I...
Hello,
I am trying to port NewLib for my OS (I am following this tutorial: http://wiki.osdev.org/Porting_Newlib), and I have some questions.
Once LibGloss is done and compiled, when exactly I'll have to use the libnosys.a that have been created? Is it when I will compile my main.c?
> mipsel-uknown-elf-gcc main.c -Llibnosys.a
M...
Hello,
I was wondering if there is a way of finding which function called the current function (at runtime) in C.
I know you could use __FUNCTION__ in gcc, but is there a way without using the C preprocessor?
Probably not.
Cheers
...
As has been discussed in several recent questions, declaring const-qualified variables in C (as opposed to const variables in C++, or pointers to const in C) usually serves very little purpose. Most importantly, they cannot be used in constant expressions.
With that said, what are some legitimate uses of const qualified variables in C? ...
I am reading GNU/Linux application programming the 2nd edition,you can reach what am reading from here.After I write the code similar to his,but it work strangely:
$ ./shell
./shell>>quit
$ ./shell
./shell>>date
Sun Aug 8 21:19:37 CST 2010
./shell>>quit
$ ./shell
./shell>>abc
execlp failed: No such file or directory
./shell>>quit
./she...
Hi,
I wrote a program in python (using standard python libraries) long ago. Now I need to write the same program in standard C due to the lack of python support for that device.
Please suggest me programs or conversion method to convert that python code into C code.
Thanks in advance.
...
Possible Duplicate:
BigInt in C?
Hey there!
I'm calculating the Fibonacci numbers in C up to 46 using an unsigned int, but I can't calculate F(47) because it's long. So, is there a way to get numbers bigger than 2^32 in C?NB: I use a 32-bit processor.
...
I have a project that links to libssl.so and I'm hitting a bug in libssl and never versions of the lib fixes it. However on the system I'm working I don't have root account so I've built libssl and prerequirements myself under $HOME/opt.
Now, when I'm doing:
./configure --prefix=`$HOME/opt`
make
the build system still uses the older ...