91学习

陪伴你每一天!

fgets()读取任意磁盘文件中的内容

#include <stdio.h>#include <process.h>void main(){ FILE *fp; char filename[30],str[30]; printf("please input filename:\n"); scanf("%s",filename); if((fp=fopen(filename,"r"))==NULL){ printf("can not open

fputs函数向文件中写入内容

#include <stdio.h>#include <process.h>void main(){ FILE *fp; char filename[30],str[30]; printf("please input filename:\n"); scanf("%s",filename); if((fp=fopen(filename,"w"))==NULL){ printf("can not open

读取文件内容

#include <stdio.h>void main(){ FILE *fp; char ch; fp=fopen("E:\\exp01.txt","r"); ch=fgetc(fp); while(ch!=EOF){ putchar(ch); ch=fgetc(fp); } printf("\n"); fclose(fp);}

编写程序实现向文件中写入内容

#include <stdio.h>#include <stdlib.h>void main(){FILE *fp;char ch;if((fp=fopen("E:\\exp01.txt","w"))==NULL){ printf("cannot open file\n"); exit(0);}ch=getchar();while(ch!='#'){   putc(ch,fp);&nbs

#line命令

#line 100 "13.7.c"#include <stdio.h>void main(){ printf("1.当前行号:%d\n",__LINE__); printf("2.当前行号:%d\n",__LINE__);}

#ifdef和#ifndef的应用

#include <stdio.h>#define STR "Believe yourself\n"int main(){#ifdef STR printf(STR);#else printf("**Don't give up**\n");#endif printf("\n");#ifndef ABC  printf("Dont't give up\n");#else 

判断体温是否为正常

#include <stdio.h>#define TEM 37int main(){#if TEM>37 printf("高烧\n");#elif TEM<36 printf("低烧\n");#else  printf("正常体温\n");#endif printf("当前温度是:%d\n",TEM); return 0;}

使用#else判断19054是否能被9527整除的偶数

#include <stdio.h>#define iInput 19054int main(){ printf("当前是:%d\n",iInput);#if iInput >0 if(iInput % 9527 == 0&&iInput%2 == 0) printf("能被9527整除的偶数\n");#else#if iInput<0 printf("当前为负数:%d\n",iInput);#

与50比较大小

#include "stdio.h"#define NUM 51void main(){ int i=0;#if NUM>50 i++;#endif#if NUM==50 i=i+50;#endif #if NUM<50 i--;#endif printf("NOW i is %d\n",i);}

头文件应用:一年长一岁

#include "stdio.h"#include "age.h"int main(){ int age=3; age=A; p("年龄是"D"岁\n",age); return 0;}