On Mon, 6 Sep 2004 22:50:43 +1000, "Pete" <> wrote:
>I'm trying to a very simple encryption key generator. I have hard coded a 10
>binary string into an array, I then want to permute that string using
>another array with element of type int for 1 to 10. Then I'm using this as
>an index to copy to an output array, but offcourse the integer 10 is reading
>the non-existent 11th element of, could someone help with a solution to my
>problem, I would prefer to get the binary string from keyboard but I had
>problems. below is the fragment I'm having problems with.
>
>#include <stdio.h>
>#include <string.h>
>
>main()
>{
> int string[10]={1,1,0,1,0,0,0,1,1,1};
> int P10[10]={3,5,2,7,4,10,1,9,8,6};
> /*int input[10];*/
> int P10_out[10];
> int i,index;
>
> /*printf("\nEnter a 10 Binary Sting: ");
> for(i=0; i<10; i++){
> scanf("%d", input[i]);
You commented out the definition of input above. This code won't
compile.
> }*/
> for(i=0; i<10; i++) {
> index = P10[i];
When i is 5, index is 10.
> P10_out[i] = string[index];
string[10] does not exist. The indices for string run from 0 to 9.
This invokes undefined behavior.
> printf("P10_out = %d\n", P10_out[i]);
> }
>}
>
>As you can see I tyied to enter from the keyboard but the binary string
>converted to an int I think
Until you show us your real code, we have no idea what you are talking
about.
<<Remove the del for email>>
|