一个小练习题,不知道为什么程序犯神经……
程序代码:#include <stdio.h>
#include <string.h>
char *get_first_character(char *name);
int main(void)
{
char first_name[10], middle_name[10], last_name[10];
char *final1, *final2;
final1 = (char *)malloc(30 * sizeof(char));
final2 = (char *)malloc(3 * sizeof(char));
puts("Please enter your first name:");
gets(first_name);
puts("Please enter your middle name:");
gets(middle_name);
puts("Please enter your last name:");
gets(last_name);
printf("%c", first_name[0]);
final1 = get_first_character(first_name);
puts(final1);
final2 = get_first_character(middle_name);
puts(final2);
strcat(final1, final2);
puts(final1);
strcat(final1, last_name);
puts(final1);
printf("Now the result is %s\n", final1);
return(0);
}
char *get_first_character(char name[])
{
char name1[3];
if(name[0] < 'z' && name[0] > 'a')
name1[0] = name[0] - 32;
else
name1[0] = name[0];
name1[1] = '.';
name1[2] = '\0';
return(name1);
}这个程序是可以通过编译器的……但是结果就比较逗逼……
不知道为什么输出奇怪的中文加上一个`
匍`
上面这样的……







自己再想了一下……

