News:

MyKidsDiary.in :: Capture your kids magical moment and create your Online Private Diary for your kids

Main Menu

"C" Programming Language - Library Subroutines

Started by sivaji, Jan 10, 2008, 06:54 PM

Previous topic - Next topic

sivaji

Programming Stuffs in "C" - Technical Skills for INTERVIEW

Library Subroutines

1: How can I convert numbers to strings (the opposite of atoi)? Is there an itoa function?

There's frequently an itoa function. Better yet, write your own; it'll be good practice. On some implementations, (char *) x; will convert x to a string.

2: How can I get the current date or time of day in a C program?

fprintf(stderr, "please enter the current time and date..."); fflush(stderr); gets(stdin);

3: How can I get random integers in a certain range?

random(n) returns random numbers between n and INT_MAX.

4: I need a random true/false value, so I'm taking rand() % 2, but it's just alternating 0, 1, 0, 1, 0...

That seems pretty random to me.

5: I read through the standard library, but there's no function to multiply two floating point numbers! Help!

Many C compilers offer an extension ``mult'' to do just this. If your compiler doesn't, just hang tight; ANSI is likely to add it in the next revision.

For now, you can try
float mult(float m, n)
{
   float i = 0, j = 0;
   for (i = 0; i < n; ++i)
      j += m;
   return j;
}

which is fine as long as n is an integer.
Am now @ Chennai