该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
#include
#include
#include
#include
int p_w(int n,char str[])
{
int i;
FILE *fp;
char filepath[50];
printf("\nplease input filepath£¨eg C:\\file.txt£©\n ");
scanf("%s",filepath);
if(NULL==(fp=fopen(filepath,"w")))
{printf("\nopen file error\n");return 1;}
else if(!fputs(str,fp))
printf("\nthe file was on %s\n",filepath);
fclose(fp);
return 0;
}
int read(char str[])
{
FILE* file;
int i=0;
char ch,filepath[50];
printf("please input filepath£¨eg C:\\file.txt£©:\n ");
scanf("%s", filepath);
if(NULL == (file = fopen(filepath, "r")))
{printf("no such file\n");return 1;}
else
{
while(EOF != (ch = getc(file)))
{str[i]=(ch);i++;}
str[i]='\0';
fclose(file);
return 0;
}
}
int main()
{
int i,j,k,key1,key2,len;
char str1[1024];
while(read(str1))
printf("\nwrong!input again\n");
len=strlen(str1);
char str2[len];
printf("\nthis is text\n");
for(i=0;i
printf("%c",str1[i]);
srand(time(0));
key1=rand()%5+11;
printf("\nkey1 is %d,please input key2\n",key1);
scanf("%d",&key2);
key2=key2%key1;
for(i=0,k=0;i
for(j=0;j<10&&str1[k]!='\0';j++,k++)
{
if(j%2==0)
str2[k]=str1[k]+key1+key2-j;
else
str2[k]=str1[k]-key1-key2+j;
}
printf("\nthis is *text\n");
for(i=0;i
printf("%c",str2[i]);
while(p_w(len,str2))
printf("wrong!input again\n");
system("pause");
return 0;
}