1 #include <stdio.h>
2 #include <stdlib.h>
3 void singing();
4 int main()
5 {
6 singing();
7 system("pause");
8 }
9
10 void singing()
11 {
12 printf("after party~after party~我已然赶不上地铁\n");
13 }
上述代码段是一个C语言函数的声明过程,首先要声明一个函数(第三行),然后定义函数(第10行),第6行调用这个函数
带参数的函数的声明
#include <stdio.h>
#include <stdlib.h>
void singing(char[]);
int main()
{
singing("新裤子");
system("pause");
}
void singing(char clipname[])
{
printf("专辑名称:%s========after party~after party~我已然赶不上地铁\n",clipname);
}
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#pragma warning(disable:4996)
char * singing(char[]);
int main()
{
char prtline[200] = {0};
strcat(prtline,singing("新裤子"));
printf("%s", prtline);
system("pause");
}
char * singing(char clipname[])
{
/*printf("专辑名称:%s========after party~after party~我已然赶不上地铁\n",clipname);*/
char finalstr[200] = {0};
strcat(finalstr, "专辑名称:");
strcat(finalstr, clipname);
strcat(finalstr, "========after party~after party~我已然赶不上地铁\n");
/*printf("%s", finalstr);*/
return finalstr;
}但凡遇到 char * 函数名 或者是 int * 函数名意味着,函数返回字符数组或者是整型数组代码行#pragma warning(disable:4996)是考虑到strcat() strcpy()函数可能被弃用的事实exit()函数-----哪怕是在自定义函数中用一下,也会导致整个main函数的退出
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#pragma warning(disable:4996)
char * singing(char[]);
int main()
{
char prtline[200] = {0};
strcat(prtline,singing("新裤子"));
printf("%s", prtline);
system("pause");
}
char * singing(char clipname[])
{
/*printf("专辑名称:%s========after party~after party~我已然赶不上地铁\n",clipname);*/
char finalstr[200] = {0};
exit("操~爷不干了");
strcat(finalstr, "专辑名称:");
strcat(finalstr, clipname);
strcat(finalstr, "========after party~after party~我已然赶不上地铁\n");
/*printf("%s", finalstr);*/
return finalstr;
}