内存中关于mem的操作

来源:百度知道 编辑:UC知道 时间:2024/09/22 21:22:26
2.将26个英文字母(小写)加上数值128,并且每5个英文字母后插入一个字符’\0’,输出到文件mem.tst中。写完文件mem.tst后,关闭文件指针。

给,已经编译运行确认:
#include<stdio.h>
#include<conio.h>

int main(void)
{
FILE *stream;
char ch=0,endofstring='\0';
int i=0,count=0;

printf("Create the File: mem.tst...\n");

if ((stream = fopen("mem.tst", "a+")) == NULL)
{
fprintf(stderr, "Cannot open output file.\n");
return 0;
}

printf("Success \n");
printf("Write Data...\n");
for(i=0;i<26;i++)
{
ch='a'+i+128;
fwrite(&ch, sizeof(ch), 1, stream);
count++;
if(count%5==0) fwrite(&endofstring, sizeof(endofstring), 1, stream);
}

printf("Success \n");
printf("Close the File: mem.tst...\n");

fclose(stream);

printf("Success \n");

getch();
return 1;
}