一个C语言程序输出序号和单词,
来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2024/07/13 21:30:55
一个C语言程序输出序号和单词,
#include
#include
#define MAX 40
int main(void)
{
FILE *fp;
char words[MAX];
int wordct = 0;
if ((fp = fopen("wordy","a+")) == NULL)
{
fprintf(stderr,"Can't open \"words\" file.\n");
exit(1);
}
/* determine current number of entries */
rewind(fp);
while (fgets(words,MAX - 1,fp) = NULL)
wordct++;
rewind(fp);
puts("Enter words to add to the file.Enter one word per line,and ");
puts("press the Enter key at the beginning of a line to terminate.");
while (gets(words) = NULL && words[0] = '\0')
fprintf(fp,"%d:%s\n",++wordct,words);
puts("File contents:");
rewind(fp); /* go back to beginning of file */
while (fgets(words,MAX - 1,fp) = NULL)
fputs(words,stdout);
if (fclose(fp) = 0)
fprintf(stderr,"Error closing file\n");
return 0;}尤其是解释一下rewind();谢谢!
#include
#include
#define MAX 40
int main(void)
{
FILE *fp;
char words[MAX];
int wordct = 0;
if ((fp = fopen("wordy","a+")) == NULL)
{
fprintf(stderr,"Can't open \"words\" file.\n");
exit(1);
}
/* determine current number of entries */
rewind(fp);
while (fgets(words,MAX - 1,fp) = NULL)
wordct++;
rewind(fp);
puts("Enter words to add to the file.Enter one word per line,and ");
puts("press the Enter key at the beginning of a line to terminate.");
while (gets(words) = NULL && words[0] = '\0')
fprintf(fp,"%d:%s\n",++wordct,words);
puts("File contents:");
rewind(fp); /* go back to beginning of file */
while (fgets(words,MAX - 1,fp) = NULL)
fputs(words,stdout);
if (fclose(fp) = 0)
fprintf(stderr,"Error closing file\n");
return 0;}尤其是解释一下rewind();谢谢!
#include
#include
#define MAX 40
int main(void)
{
FILE *fp;
char words[MAX];
int wordct = 0;
if ((fp = fopen("wordy","a+")) == NULL) //打开文件,是指针fp指向文件wordy
{
fprintf(stderr,"Can't open \"words\" file.\n");
exit(1);
}
/* determine current number of entries */
rewind(fp); //rewind()是一个反绕函数,作用是使指针回到文件的开头,在对文件读写的过程中,指针是一直变化的,但是这个函数会把指针重新置在文件的开头
while (fgets(words,MAX - 1,fp) != NULL) // 统计文件中单词个数
wordct++;
rewind(fp);
puts("Enter words to add to the file.Enter one word per line,and ");
puts("press the Enter key at the beginning of a line to terminate.");
while (gets(words) != NULL && words[0] != '\0')
fprintf(fp,"%d:%s\n",++wordct,words); //追加新单词到文件中,并标注序号wordct
puts("File contents:");
rewind(fp); /* go back to beginning of file */
while (fgets(words,MAX - 1,fp) != NULL)
fputs(words,stdout);
if (fclose(fp) != 0)
fprintf(stderr,"Error closing file\n");
return 0;}
#include
#define MAX 40
int main(void)
{
FILE *fp;
char words[MAX];
int wordct = 0;
if ((fp = fopen("wordy","a+")) == NULL) //打开文件,是指针fp指向文件wordy
{
fprintf(stderr,"Can't open \"words\" file.\n");
exit(1);
}
/* determine current number of entries */
rewind(fp); //rewind()是一个反绕函数,作用是使指针回到文件的开头,在对文件读写的过程中,指针是一直变化的,但是这个函数会把指针重新置在文件的开头
while (fgets(words,MAX - 1,fp) != NULL) // 统计文件中单词个数
wordct++;
rewind(fp);
puts("Enter words to add to the file.Enter one word per line,and ");
puts("press the Enter key at the beginning of a line to terminate.");
while (gets(words) != NULL && words[0] != '\0')
fprintf(fp,"%d:%s\n",++wordct,words); //追加新单词到文件中,并标注序号wordct
puts("File contents:");
rewind(fp); /* go back to beginning of file */
while (fgets(words,MAX - 1,fp) != NULL)
fputs(words,stdout);
if (fclose(fp) != 0)
fprintf(stderr,"Error closing file\n");
return 0;}
一个C语言程序输出序号和单词,
请设计一个C语言程序,能实现这个功能:输入10个单词,按字典序输出各单词
下面是一个C语言程序 关于输出三个数中的最大值和最小值
C语言输出一个菱形图案(有程序)
用c语言编写一个程序,输出下列雪花图案!
用C语言编写一个程序输出菱形图案
编写一个程序,输入两个整数,计算并输出它们的和,乘积,差,商和余数,C语言,
如何用c语言编一个比较三个数大小的程序,并输出最大值和最小值
C语言程序编写 输入一个大写字母,输出字母表中它前面的字母和它后面的字母
c语言中试编写一个程序,输入abc三个整型变量的值,输出最大max和最小值min
编写一个c语言程序:输入整数,数目不超过100个,然后分别以升序和降序输出这些数
C语言程序题:任意输入十个数,输出最大最小和平均数,这个程序咋么写啊?