适用于Windows,但不适用于HPUX,请帮助 [英] Works on Windows but not on HPUX, Help Please

查看:74
本文介绍了适用于Windows,但不适用于HPUX,请帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




此代码在win和linux上运行正常但在hpux上运行不正常。全部用gcc编译

。有人可以帮忙吗?


/ ******************************** ****************** *************************** /

/ *

* /

/ *加密

* /

/ *

* /

/ ********************************** **************** *************************** /

/ *描述:只是加密字符串的实用程序功能。在配置文件中使用

* /

/ *简单密码存储。

* /

/ *

* /

/ ******************************* ******************* *************************** /
void encrypt(char str [],int key)

{

unsigned int i;

for(i = 0 ;我< strlen(str); ++ i)

{

str [i] = str [i] - key;

}

}


/ **************************** ********************** *************************** /

/ *

* /

/ *解密

* /

/ *

* /

/ ****************************** ******************** *************************** /

/ *描述:简单地解密字符串的实用程序函数。在配置文件中使用

* /

/ *简单密码存储。

* /

/ *

* /

/ ******************************* ******************* *************************** /
void decrypt(char str [],int key)

{

unsigned int i;

for(i = 0 ; i< strlen(str); ++ i)

{

str [i] = str [i] + key;

}

}

解密功能甚至缩短了长度,正如你所看到的那样,

不应该发生,也不会在其他操作系统上使用


任何帮助都会很棒,谢谢

亲切的问候

Danny

Hi,

This code works fine on win and linux but not on hpux. All is compiled
with gcc. Can anyone help please?

/************************************************** ***************************/
/*
*/
/* encrypt
*/
/*
*/
/************************************************** ***************************/
/* Description: Utility function that simply encrypts a string. Used
for */
/* simple password storage in the config file.
*/
/*
*/
/************************************************** ***************************/
void encrypt(char str[],int key)
{
unsigned int i;
for(i=0;i<strlen(str);++i)
{
str[i] = str[i] - key;
}
}

/************************************************** ***************************/
/*
*/
/* decrypt
*/
/*
*/
/************************************************** ***************************/
/* Description: Utility function that simply decrypts a string. Used
for */
/* simple password storage in the config file.
*/
/*
*/
/************************************************** ***************************/
void decrypt(char str[],int key)
{
unsigned int i;
for(i=0;i<strlen(str);++i)
{
str[i] = str[i] + key;
}
}
The decrypt function even shortens the length, which as you can see,
shouldnt happen and doesnt on other OSs

Any help would be great, thanks
Kind regards
Danny

推荐答案

在文章< 11 ********************* @ i40g2000cwc.googlegroups中。 com>,

Smurff< da *********** @ gmail.com>写道:
In article <11*********************@i40g2000cwc.googlegroups. com>,
Smurff <da***********@gmail.com> wrote:
这段代码在win和linux上运行正常但在hpux上运行不正常。所有都是用gcc编译的。有人可以帮忙吗?


你真的没说过你看到了什么症状。

void encrypt(char str [],int key)
{
unsigned int i;
for(i = 0; i< strlen(str); ++ i)
{
str [i] = str [i] - key;
}
}
void decrypt(char str [],int key)
{
unsigned int i;
for(i = 0; i< strlen( str); ++ i)
{
str [i] = str [i] + key;
}
}
解密函数甚至缩短了长度,正如你所看到的那样,
不应该发生,也不会在其他操作系统上发生
This code works fine on win and linux but not on hpux. All is compiled
with gcc. Can anyone help please?
You didn''t really say what symptoms you saw.
void encrypt(char str[],int key)
{
unsigned int i;
for(i=0;i<strlen(str);++i)
{
str[i] = str[i] - key;
}
} void decrypt(char str[],int key)
{
unsigned int i;
for(i=0;i<strlen(str);++i)
{
str[i] = str[i] + key;
}
} The decrypt function even shortens the length, which as you can see,
shouldnt happen and doesnt on other OSs




如果键恰好匹配str []中的任何字符,那么减法

将在相应的位置产生一个0,那就是

对strlen来说会缩短字符串的效果()

关注。


但是如果在某些具有相同输入的系统上没有发生这种情况,那么我的假设就是你遇到的情况差异
关于char是签名还是未签名。

-

重要的是要记住,当涉及到法律,计算机

从不制作副本,只有人类制作副本。计算机给出了

命令,而非许可。只有人才能获得许可。

- Brad Templeton



If key happens to match any character in str[] then the subtraction
is going to produce a 0 at the corresponding position, and that is
going to have the effect of shortening the string as far as strlen()
is concerned.

But if that isn''t happening for you on some systems with the same input,
then my hypothesis would be that you are encountering differences
as to whether char is signed or unsigned.
--
"It is important to remember that when it comes to law, computers
never make copies, only human beings make copies. Computers are given
commands, not permission. Only people can be given permission."
-- Brad Templeton


Walter Roberson写道:
Walter Roberson wrote:
Smurff< da *********** @ gmail.com>写道:

In article <11*********************@i40g2000cwc.googlegroups. com>,
Smurff <da***********@gmail.com> wrote:
此代码在win和linux上工作正常,但在hpux上没有。
所有都是用gcc编译的。有人可以帮忙吗?
This code works fine on win and linux but not on hpux.
All is compiled with gcc. Can anyone help please?



你没说真正的症状。



You didn''t really say what symptoms you saw.

void encrypt(char str [],int key)
{
unsigned int i;
for(i = 0; i< strlen(str); ++ i)
{
str [i] = str [i] - key;
}
}
void encrypt(char str[],int key)
{
unsigned int i;
for(i=0;i<strlen(str);++i)
{
str[i] = str[i] - key;
}
}


void decrypt(char str [],int key)
{
unsigned int i;
for(i = 0; i< strlen(str); ++ i)
{
str [i] = str [i] + key;
}
}
void decrypt(char str[],int key)
{
unsigned int i;
for(i=0;i<strlen(str);++i)
{
str[i] = str[i] + key;
}
}


解密函数甚至缩短了长度,正如您所看到的那样,
不应该发生在其他操作系统上
The decrypt function even shortens the length, which as you can see,
shouldnt happen and doesnt on other OSs



如果键恰好匹配str []中的任何字符,那么减法
将在相应的位置产生一个0,那就是
就strlen()
而言,具有缩短字符串的效果。

但如果不发生这种情况你在一些具有相同输入的系统上,然后我的假设是你遇到了关于char是签名还是未签名的差异。



If key happens to match any character in str[] then the subtraction
is going to produce a 0 at the corresponding position, and that is
going to have the effect of shortening the string as far as strlen()
is concerned.

But if that isn''t happening for you on some
systems with the same input,
then my hypothesis would be that you are encountering differences
as to whether char is signed or unsigned.






实现定义的行为可能还有问题

当char签名时和减法的​​结果

不在char的范围内。


如果key的值是INT_MIN,那么
将导致加密中的未定义行为。


-

pete



There might also be a problem with
implementation defined behavior
when char is signed and the result of the subtraction
isn''t within the range of char.

If the value of key is INT_MIN,
that would cause undefined behavior in encrypt.

--
pete


Smurff写道:
Smurff wrote:


这段代码在win和linux上运行正常但在hpux上运行不正常。所有都是用gcc编译的。有人可以帮忙吗?
解密功能甚至缩短了长度,正如你所看到的那样,
不应该在其他操作系统上发生
Hi,

This code works fine on win and linux but not on hpux. All is compiled
with gcc. Can anyone help please? The decrypt function even shortens the length, which as you can see,
shouldnt happen and doesnt on other OSs




请发一个COMPLETE最小演示问题的程序。

我们需要看到你的测试驱动程序以及例行程序。什么关键?什么

字符串?


Brian



Please post a COMPLETE minimal program that demonstrates the problem.
We need to see your test driver as well as the routine. What key? What
string?


Brian


这篇关于适用于Windows,但不适用于HPUX,请帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆