- 论坛徽章:
- 0
|
我想把一个文本里的每一个字符都做一个异或运算。
结果发现一个问题,无论你多长的文本,运算只做了只前十几个字符的异或就停止了,下面的死也不运算了。
何解。。。。。
代码:
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
encode(char string[])
{
int len,i;
len=strlen(string);
printf("len:%d\n",len);
for(i=0;i<len;i++)
{
string[i]^='x';
}
}
main()
{
int fd;
char buffer[200];
fd=open("/root/tt.txt",O_RDONLY);
perror("open:");
read(fd,buffer,100);
close(fd);
encode(buffer);
printf("buffer:%s\n",buffer);
encode(buffer);
printf("buffer:%s\n",buffer);
}
文本内容:
Major opcode: 20 (X_GetProperty)
Resource id: 0y2401373
kdeinit4: preparing to launch gusrbinirefoy
kdeinit4: preparing to launch gusrlib64libkdeinit4_kfmclient.so
deinit4: preparing to launch gusrlib64libkdeinit4_konqueror.so
Launched ok, pid = 18203
kdeinit4: preparing to launch gusrlib64kde4kio_sysinfo.so
kio_sysinfo(18209) kdemain: *** Starting kio_sysinfo
kio_sysinfo(18209) kio_sysinfoProtocol::glInfo: found_line true
kio_sysinfo(18209) kio_sysinfoProtocol::memoryInfo: total 4921393152 free 4390510592 unit 1
*** nss-shared-helper: Shared database disabled (set NSS_USE_SHARED_DB to enable).
kio_sysinfo(18182) kdemain: *** kio_sysinfo Done
kio_sysinfo(18209) kio_sysinfoProtocol::memoryInfo: total 4925239296 free 4387401728 unit 1
kio_sysinfo(18209) kio_sysinfoProtocol::memoryInfo: total 4924084224 free 4386779136 unit 1
kio_sysinfo(18209) kio_sysinfoProtocol::memoryInfo: total 4926287872 free 4391145472 unit 1
Could not read Gnome Bookmarks file groot.gtk-bookmarks: Could not find file "root.gtk-bookmarks".
结果:
open:: Success
len:101
第一次异或:
buffer:XX5
XBXJHXP '?
(
QrXX*
XBXXHJLHIKOKr
LBX
X
X X
y
len:101
第二次异或原还:
buffer: Major opcode: 20 (X_GetProperty)
Resource id: 0y2401373
kdeinit4: preparing to launch gusrbinfi |
|