易截截图软件、单文件、免安装、纯绿色、仅160KB

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


相关文档:

pku 2115 C Looooops 同余定理

 #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 ......

C/C++中的日期和时间 time_t与struct tm转换

 摘要:
本文从介绍基础概念入手,探讨了在C/C++中对日期和时间操作所用到的数据结构和函数,并对计时、时间的获取、时间的计算和显示格式等方面进行了阐述。本文还通过大量的实例向你展示了time.h头文件中声明的各种函数和数据结构的详细使用方法。
关键字:UTC(世界标准时间),Calendar Time(日历时间),epoch ......

C/C++ 常见面试题

 
1.指针和引用有什么分别;如果传引用比传指针安全,为什么?如果我使用常量指针难道不行吗?
     (1) 引用在创建的同时必须初始化,即引用到一个有效的对象;而指针在定义的时候不必初始化,可以在定义后面的任何地方重新赋值.
     (2) 不存在NULL引用,引用必 ......

C++中extern “C”含义深层探索

(转)C++中extern “C”含义深层探索
 
 
1.引言
  C++语言的创建初衷是“a better C”,但是这并不意味着C++中类似C语言的全局变量和函数所采用的编译和连接方式与C语言完全相同。作为一种欲与C兼容的语言,C++保留了一部分过程式语言的特点(被世人称为“不彻底地面向对象&rdquo ......

GNU C library 笔记1

内容:Introduction 和 Error Reporting
1. glibc 所实现全部或部分规范下的功能有
ISO C: The international standard for the C programming language.
POSIX: The ISO/IEC 9945 (aka IEEE 1003) standards for operating systems.
Berkeley Unix: BSD and SunOS.
SVID: The System V Interface Description.
X ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号