C/C++——小编谈C语言函数那些事(7)
C程序是由一组或是变量或是函数的外部对象组成的。 函数是一个自我包含的完成一定相关功能的执行代码段。下面小编和大家分享下C语言中的函数。
1. fgetc函数
fgetc函数的功能是从流中读取字符,其用法是:int fgetc(FILE *stream); 程序例子如下:
#include <string.h>
#include <stdio.h>
#include <conio.h>
int main(void)
{
FILE *stream;
char string[] = "This is a test";
char ch;
/* open a file for update */
stream = fopen("DUMMY.FIL", "w+");
/* write a string into the file */
fwrite(string, strlen(string), 1, stream);
/* seek to the beginning of the file */
fseek(stream, 0, SEEK_SET);
do
{
/* read a char from the file */
ch = fgetc(stream);
/* display the character */
putch(ch);
} while (ch != EOF);
fclose(stream);
return 0;
}
2. fgetchar函数
fgetchar函数的功能是关闭打开流,其用法是:int fgetchar(void); 程序例子如下:
#include <stdio.h>
int main(void)
{
char ch;
/* prompt the user for input */
printf("Enter a character followed by \
<Enter>: ");
/* read the character from stdin */
ch = fgetchar();
/* display what was read */
printf("The character read is: '%c'\n",
ch);
return 0;
}
3. fread函数
fread函数的功能是从一个流中读数据,其用法是:int fread(void *ptr, int size, int nitems, FILE *stream); 程序例子如下:
#include <string.h>
#include <stdio.h>
int main(void)
{
FILE *stream;
ch
相关文档:
C/C++/VC++ 变量命名规则
是VC++的么?
4.变量风格
变量尽量采用匈牙利命名法,同时结合VC的原则;一般情况下,变量的取名方式为:
<scope><prefix><qualifier>
有关项目的全局变量必须用g_开始,类成员变量用m_,局部变量若函数较大则可考虑用l_用以显示说明其是局部变量。
前缀
类型
示例
g_
......
(转)C++中extern “C”含义深层探索
1.引言
C++语言的创建初衷是“a better C”,但是这并不意味着C++中类似C语言的全局变量和函数所采用的编译和连接方式与C语言完全相同。作为一种欲与C兼容的语言,C++保留了一部分过程式语言的特点(被世人称为“不彻底地面向对象&rdquo ......
C程序是由一组或是变量或是函数的外部对象组成的。 函数是一个自我包含的完成一定相关功能的执行代码段。下面小编和大家分享下C语言中的函数。
1. fclose函数
fclose函数的功能是关闭一个流,其用法是:int fclose(FILE *stream); 程序例子如下:
#include <string.h& ......