|
1. Write a function that prints the binary representation of an unsigned integer using only putchar() for output
2. Memory Management/Pointer manipulation
Write a function that allows you to remove a substring from a string and returns a new string that uses only the amount of storage needed
Assume: All arguments are always valid
The original string should remain untouched
Use the following function prototype
char * remove_substr(char *str, int pos, int length);
3. Data structures
Implement a circular queue of size n using an array. Use the given fragments for your implementation
typedef stuct QUEUE{
int head, tail;
void * data[N];
}queue;
void init-queue()
{
}
int queue(void *data)
{
}
void * dequeue()
{
}
4. Problem solving/operating systems
A multitasking OS has a producer program that writes data to a buffer and consumer one that reads that data and prints it. Show the work that needs to be done to make sure this works smoothly.
5. C syntax
Identify all the errors in the following piece of C code. Assuming you fix it so it compiles correctly. What would it print? (be sure to specify any assumptions)
void init_array(unsigned int array[])
{
int size = sizeof(array);
int i;
for(i=0; i<size; i++)
array=-1;
}
void main()
{
char * string=”Here is rather long constant to fit my needs”;
char * another_string;
unsigned int array[11];
init_array(&array[0]);
another_string=(char*)malloc(strlen(string));
strcpy(another_string,string);
for(i=0; i<=40; i+=4){
array[i/4]=int(*)string;
printf(“%s”, (char *) array);
} |
|