any ideas (integer encryption)
I'm trying to come up with a way to take a buffer of integers such as the numbers '123456' and translate them singly into their character reprenstation form....
for use with network hand shake of a server/client I am creating.
I've tried quite a few ways of looping through each index of a character array to do this, but to no avail....
Code:
int CreateHandShake(char *buf)
{
char data[10];
char a22[1];
char *b22;
strcpy(data, "123456");
b22 = data;
for(int cnt=0; cnt < 4; cnt++)
{
strncpy(a22,b22,1);
b22 + 1;
strcpy(buf,a22);
strcpy(a22, "");
}
return 0;
}
any ideas? anyone?
Re: any ideas (integer encryption)
Quote:
Originally posted by TokersBall_CDXX
I'm trying to come up with a way to take a buffer of integers such as the numbers '123456' and translate them singly into their character reprenstation form....
for use with network hand shake of a server/client I am creating.
I've tried quite a few ways of looping through each index of a character array to do this, but to no avail....
Code:
int CreateHandShake(char *buf)
{
char data[10];
char a22[1];
char *b22;
strcpy(data, "123456");
b22 = data;
for(int cnt=0; cnt < 4; cnt++)
{
strncpy(a22,b22,1);
b22 + 1;
strcpy(buf,a22);
strcpy(a22, "");
}
return 0;
}
any ideas? anyone?
not sure what you're trying to do here, but
b22 + 1;
does nothing, you probably mean ++b22;
strncpy(a22,b22,1);
is the same as
*a22=*b22;
I've tried type casting as well,
Code:
int CreateHandShake(char *buf, HWND hDlg2)
{
char data[10];
char a22[1];
int c22;
char *b22;
strcpy(data, "123156");
b22 = data;
for(int cnt=0; cnt < 6; cnt++)
{
c22=(int)data[cnt];
buf[cnt] = (char)c22;
}
return 0;
}
doesn't translate the character though
buf = 123156
instead of the character representation?
hmmm...
any ideas?
Re: I've tried type casting as well,
Use atoi() defined in the <cstdlib> header to convert from text to int.
Re: Re: I've tried type casting as well,
Quote:
Originally posted by transcendental
Use atoi() defined in the <cstdlib> header to convert from text to int.
Code:
{
char data[10];
char a22[1];
int c22;
strcpy(data, "123156");
for(int cnt=0; cnt < 6; cnt++)
{
c22=atoi(data[cnt]);
buf[cnt] = (char)c22;
}
return 0;
}
gives me an error because data[cnt] isn't a buffer/string ending with /0....
Error example.c: 423 type error in argument 1 to `atoi'; found `char' expected `pointer to char'
Compilation + link time:3.5 sec, Return code: 1
I've already tried that..hmmm
I've also tried using a pointer, and stepping the location of the memmory address incremented to each character of data.... also doesn't work.