090928日c语言学习日记(文件I/O)
#include<stdio.h>
#include<stdlib.h>
#define MAX 41
static int i=0;
int main(void)
{
FILE *fp;
char words[MAX];
if((fp=fopen("words","a+"))==NULL)
{
fprintf(stdout,"Can't open \" word\" file\n");
exit(1);
}
puts("Enter words to add to the file,press the enter.");
puts("Key at the begining of a line to terminate.");
while(gets(words)!=NULL&&words[0]!='\0')
{
fprintf(fp,"%s",words);
i++;
}
rewind(fp);
while(fscanf(fp,"%s",words)==1)
{
puts(words);
}
if(fclose(fp)!=0)
{
fprintf(stderr,"Error closing file.\n");
}
return 0;
}
#include<stdio.h>
#include<stdlib.h>
#define MAX 2000
int main(void)
{
FILE *fp;
char words[MAX];
int wordct=0;
if((fp=fopen("words","a+"))==NULL)
{
fprintf(stderr,"Can't open \" word\" file\n");
exit(1);
}
rewind(fp);
while (fgets(words, MAX - 1, fp) != NULL)
wordct++;
rewind(fp);
puts("Enter words to add to the file,press the enter.");
puts("Key at the begining of a line to terminate.");
while(gets(words)!=NULL&&words[0]!='\0')
{
fprintf(fp,"%d:%s",++wordct,words);
}
puts("File contents:");
rewind(fp);
while(fgets(words,MAX-1,fp)!=NULL)
{
fputs(words,stdout);
}
if(fclose(fp)!=0)
{
fprintf(stderr,"Error closing file.\n");
}
return 0;
}
/*文件名由用户输入,建立一个循环,让用户输入文件位置,
则打印位置到下一个换行符之间的字符,当输入非数字字符时退出*/
#include<stdio.h>
#include<stdlib.h>
#include<ctype.h>
#define MAX 41
int main(void)
{
FILE *fp;
char ch;
char file[MAX];
long address;
puts("请输入文件名");
gets(file);
if((fp=fopen(file,"rb"))==NULL)
{
fprintf(stderr,"Can't open the %s\n",file);
exit(1);
}
printf("请输入一个文件位置\n");
while(1)
{
scanf("%ld",&address);
if(isdigit(address))
{
break;
}
fseek(fp,address,SEEK_SET);
while((ch=getc(fp))!='\n' && (ch=getc(fp)
相关文档:
《C专家编程》学习总结2
转自 : http://blog.chinaunix.net/u2/87570/showart_2120069.html
编译器做了些什么
图1:编译器通常分割成几个更小的程序
静态链接与动态链接
  ......
1. 怎样建立和理解非常复杂的声明?例如定义一个包含N 个指向返回指向字符的指针的函数的指针的数组?
这个问题至少有以下3 种答案:
1. char *(*(*a[N])())();
2. 用typedef 逐步完成声明:
typedef char *pc; /* 字符指针*/
typedef pc fpc(); /* 返回字符指针的函数*/
typedef fpc *pfpc; /* 上面函数的指针*/ ......
oracle中pro*c的学习
一 Pro*C 程序概述:
1.什么是Pro*C程序
在ORACLE数据库管理和系统中, 有三种访问数据库的方法;
(1) 用SQL*Plus, 它有SQL命令以交互的应用程序访问数据库;
(2) 用第四代语言应用开发工具开发的应用程序访问数据库,这些工具有SQL*froms,QL*Reportwriter,SQL*Menu等;
(3) 利用在 ......
1) goto
goto 只能在一个函数内跳转。建议少用,使得程序维护起来容易出错;但是,在有多个循环情况下跳转,有时用goto可以使得问题变得简单。
class A
{
public:
A(){}
~A(){}
};
&nbs ......
把输入的一串字符转成数组,转成链表,然后删去其中指定的字符,在尾部添加一个字符。
(程序还不完善,没有对输错的情况进行处理,,暂时先这样吧。。= =。)
#include<stdio.h>
#include<malloc.h>
#define LEN sizeof(struct link)
struct link
{
char ch;
struct link *next;
}*string;
char a ......