Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Problem with binary strings

Reply
Thread Tools

Problem with binary strings

 
 
Pete
Guest
Posts: n/a
 
      09-06-2004
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]);
}*/
for(i=0; i<10; i++) {
index = P10[i];
P10_out[i] = string[index];
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



 
Reply With Quote
 
 
 
 
Barry Schwarz
Guest
Posts: n/a
 
      09-06-2004
On Mon, 6 Sep 2004 22:50:43 +1000, "Pete" <(E-Mail Removed)> 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>>
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
(8-bit binary to two digit bcd) or (8-bit binary to two digit seven segment) Fangs VHDL 3 10-26-2008 06:41 AM
Boost serialization: Problem reading strings from binary archive mkvenkit.vc@gmail.com C++ 2 11-09-2007 05:06 AM
Are C++ strings binary strings? ruffiano C++ 9 11-03-2006 09:01 PM
Strings, Strings and Damned Strings Ben C Programming 14 06-24-2006 05:09 AM
Problem with binary strings Pete C Programming 2 09-08-2004 05:29 AM



Advertisments