Apple Interview Question
Quality Assurance EngineersCountry: United States
Interview Type: In-Person
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include<stdlib.h>
#include <math.h>
#include <string.h>
char * create(int len)
{
char my_str[100]={' ', ' ', ' '};
char *str= (char *)malloc(len+1);
// just copy based on the length drop everything else
strncpy(str,my_str,len+1);
return str;
}
int main()
{
char *str2 = create(2);
printf("%s\n", str2);
getchar();
return 0;
}
- D-Unit April 20, 2013