Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
1. To achieve the following function, if the parameter is greater than 10, greater than 10 is printed, or printing is less than 10
void is_larger_then_10(int val);
Solution: (* prov-then.c)
void is_larger_then_10(int val){
if(val>10){
printf("larger then 10\n");
}else{
printf("smaller then 10\n");
}
}
2. To achieve the following function, if the string like "abc", the print find abc, or do not print any information void is_find (char * str);
Solution: (* prov-print.c)
void is_find(char *str){
if(0==strcmp(str,"abc")){
printf("find abc");
}
}
3. What is the difference between the following two functions
void f1()
{
printf("hello");
}
void f2()
{
printf("hello\n");
}
Solution: (* Note)
\ n: 1) Wrap;
2) printf content is stored in the buffer encounter \ n can be printed out directly.
4. implement a function, initialize the following structure
struct Area { int x;
int y;
struct Area *next;
};
void init_area(struct Area *area);
Solution: (* Note moderation, simply direct initialization prov-struct.c)
struct Area {
int x;
int y;
struct Area *next;
};
void init_area(struct Area *area){
area->x=1;
area->y=2;
area->next=NULL;
}
5. Implement mystrcpy
char *mystrcpy(char *dst, char *src);
Solution: (* Note # prov-strcpy.c)
char *mystrcpy(char *dst, char *src){
char *p=dst; //保存dst的首地址
while(*src!='\0'){ //结束条件
*dst++=*src++;
}
*dst='\0'; //结束符'\0'
return p;
}
Summary: The fifth question the need to strengthen control, the first time to write some some small problems, keep in mind three steps.
Please disregard the above solution behind the brackets! ! ! Just make a mark only, no other meaning.