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
相关文档:
#include <stdio.h>
long long mod(long long a,long long b)
{
return (a % b + b) % b;
}
struct triple
{
long long d,x,y;
};
long long Euclid(long long a,long long b)
{
if(b == 0)
return a;
else
retu ......
我在写代码的时候喜欢使用宏,不仅使代码看起来整洁,而且用好了还能极大的减轻编码的工作量,但是如果使用不当的话,出了问题查找起来就就非常的难了,下面的总结大部分是从网上看到的,也有一些是我自己在工作中总结出来的。
宏使用中的常见的基础问题
1. 防止一个头文件被重复包含
#ifndef BOD ......
摘要:
本文从介绍基础概念入手,探讨了在C/C++中对日期和时间操作所用到的数据结构和函数,并对计时、时间的获取、时间的计算和显示格式等方面进行了阐述。本文还通过大量的实例向你展示了time.h头文件中声明的各种函数和数据结构的详细使用方法。
关键字:UTC(世界标准时间),Calendar Time(日历时间),epoch ......
一 :解决C或C++中的multiple definition of问题
server.cpp
clientp2p.cpp
#include "exception.h"
#include "clientp2p.h"
clientp2p.h
中写有所有的全局变量及其初始化值
和函数声明
1.server.cpp中:
引用
:
#include "clientp2p.h"
int Main(....)
{
...
}
2.clientp ......