RELATEED CONSULTING
相关咨询
选择下列产品马上在线沟通
服务时间:8:30-17:00
你可能遇到了下面的问题
关闭右侧工具栏

新闻中心

这里有您想知道的互联网营销解决方案
C语言文件移位函数 C语言移位运算符

c语言文件指针位移

因为ftell函数的作用就是得到当前指针的位置,

主要从事网页设计、PC网站建设(电脑版网站建设)、wap网站建设(手机版网站建设)、响应式网站建设、程序开发、微网站、成都微信小程序等,凭借多年来在互联网的打拼,我们在互联网网站建设行业积累了丰富的网站设计、网站建设、网络营销经验,集策划、开发、设计、营销、管理等多方位专业化运作于一体,具备承接不同规模与类型的建设项目的能力。

而你写的这个fseek(fp,0,SEEK_END); 指针的位置就是在文件末尾 没有移动

还有指针是以字节为单位 移动的么

就是D了

c语言:若想把文件位置指针从当前位置后移动若干字节,可调用( )函数来实现

fseek()

fseek

函数名: fseek

功 能: 重定位流上的文件指针

用 法: int fseek(FILE *stream, long offset, int fromwhere);

程序例:

#include stdio.h

long filesize(FILE *stream);

int main(void)

{

FILE *stream;

stream = fopen("MYFILE.TXT", "w+");

fprintf(stream, "This is a test");

printf("Filesize of MYFILE.TXT is %ld bytes\n", filesize(stream));

fclose(stream);

return 0;

}

long filesize(FILE *stream)

{

long curpos, length;

curpos = ftell(stream);

fseek(stream, 0L, SEEK_END);

length = ftell(stream);

fseek(stream, curpos, SEEK_SET);

return length;

}

编辑词条

C语言(文件的移位与加密解密)

这道题,并不难,只是楼主,没有说清,是就字母移位吗?

但是看你的例子,有不全是。

程序如下:

#include stdio.h

#include stdlib.h

FILE *source;//源文件

FILE *destination;//目标文件

int key;//密钥

char file[100];//文件名

void encryption()//加密

{

char ch;

printf("请输入要加密的文件名\n");

scanf("%s",file);

if((source=fopen(file,"r"))==NULL)

{

printf("无法打开文件!\n");

exit(0);

}

printf("请输入加密后的文件名\n");

scanf("%s",file);

if((destination=fopen(file,"w"))==NULL)

{

printf("无法创建文件!\n");

exit(0);

}

printf("请输入密钥\n");

scanf("%d",key);

ch=fgetc(source);

while(ch!=EOF)

{

if(ch=='\n')

{

fputc(ch,destination);

ch=fgetc(source);

continue;

}

ch+=key;

fputc(ch,destination);

ch=fgetc(source);

}

fclose(source);

fclose(destination);

}

void decrypt()//解密

{

char ch;

printf("请输入要解密的文件名\n");

scanf("%s",file);

if((source=fopen(file,"r"))==NULL)

{

printf("无法打开文件!\n");

exit(0);

}

printf("请输入加密后的文件名\n");

scanf("%s",file);

if((destination=fopen(file,"w"))==NULL)

{

printf("无法创建文件!\n");

exit(0);

}

printf("请输入密钥\n");

scanf("%d",key);

ch=fgetc(source);

while(ch!=EOF)

{

if(ch=='\n')

{

fputc(ch,destination);

ch=fgetc(source);

continue;

}

ch-=key;

fputc(ch,destination);

ch=fgetc(source);

}

fclose(source);

fclose(destination);

}

int main()//主函数提供菜单

{

int choice=0;

printf("******************\n");

printf("1 文件加密\n");

printf("2 文件解密\n");

printf("3 退出\n");

printf("******************\n");

printf("请输入1 2 3选择操作\n");

scanf("%d",choice);

switch(choice)

{

case 1:encryption();break;

case 2:decrypt();break;

case 3:break;

}

return 0;

}

C语言编程题:移位函数,既能循环左移又能循环右移

#include stdio.h

#include math.h

unsigned fun(unsigned num, int n)

{

if(n  0)

{

//sizeof(unsigned)*8计算变量所占位数,如int型占32位

return (num  (sizeof(unsigned)*8 - n)) | (num  n); //先高位移动,再低位移动后,两者按位或,相当把低位溢出的又添加到了高位,实现了循环的效果 

else 

{

return (num  (sizeof(unsigned)*8 - abs(n))) | (num  abs(n));

}

}

void main(void) 

{

printf("%u\n", fun(2, -34));

}


网页名称:C语言文件移位函数 C语言移位运算符
网页链接:http://sczitong.cn/article/hpgopj.html