Wednesday, April 15, 2009

Another Interview

1. The Zune problem. That is wrong here is that an infinite loop happens when days = 366.

year = ORIGINYEAR; /* = 1980 */

while (days > 365)
{
if (IsLeapYear(year))
{
if (days > 366)
{
days -= 366;
year += 1;
}
}
else
{
days -= 365;
year += 1;
}
}

2. Write a reverse string method.

void ReverseString(char* str)
{
char temp = '';
int length = strlen(str);
for (int i = 0; i < length/2; i++)
{
temp = str[i];
str[i] = str[length-i-1];
str[length-i-1] = temp;
}
}

3. What does this code do
The answer is that it is strcmp

int foo(char* a, char*b)
{
int i;
for (i=0; a[i]==b[i]; i++)
{
if{str[i]== '\n')
{
return 0;
}
}
return a[i]-b[i];
}