Entering a binary string

P

Pete

Sorry for the ambiguity of my last post, What I am try to do is enter a 10
bit binary string
eg: 1110001010 and then permute them into an array using an array containing
3,5,2,7,4,10,1,9,8,6 as the index, so the 1st bit will be in the P10_out[3],
2nd bit in P10_out[5] and so on. I am sure the problem is to do with the
input string, it is each 1 and 0 of the input is not being read as
individual elements. Your help is much appreciated.

#include <stdio.h>
#include<string.h>

main()
{
int P10[10]={3,5,2,7,4,10,1,9,8,6};
int P10_out[10];
int i,index;
int input[10];

printf("\nEnter a 10 Binary Sting: ");
for(i=0; i<10; i++){
scanf("%c", &input);
}
for(i=0; i<10; i++) {
index = P10;
P10_out = input[index-1];
printf("P10_out = %d\n", P10_out);
}
}
 
U

Ulrich Eckhardt

Pete said:
Sorry for the ambiguity of my last post, What I am try to do is enter
a 10 bit binary string eg: 1110001010 and then permute them into an
array using an array containing 3,5,2,7,4,10,1,9,8,6 as the index, so
the 1st bit will be in the P10_out[3], 2nd bit in P10_out[5] and so
on.
I am sure the problem is to do with the input string, it is each 1
and 0 of the input is not being read as individual elements. Your
help is much appreciated.

You have to help yourself first. First, you have (at least) two subtasks,
as you described yourself. Solve both of them independently first.
Secondly, you start referring a problem but have so far neglected to tell
us what that problem is. Thirdly, your program shows one line that shows
that you have not read the FAQ and either turned off warnings or ignore
them.

Sorry, but I'm not willing to do your work for you, but hope my answers
still help.

Uli
 
T

Thomas Matthews

Pete said:
Sorry for the ambiguity of my last post, What I am try to do is enter a 10
bit binary string
eg: 1110001010 and then permute them into an array using an array containing
3,5,2,7,4,10,1,9,8,6 as the index, so the 1st bit will be in the P10_out[3],
2nd bit in P10_out[5] and so on. I am sure the problem is to do with the
input string, it is each 1 and 0 of the input is not being read as
individual elements. Your help is much appreciated.

#include <stdio.h>
#include<string.h>

main()
{
int P10[10]={3,5,2,7,4,10,1,9,8,6};
int P10_out[10];
int i,index;
int input[10];

printf("\nEnter a 10 Binary Sting: ");
for(i=0; i<10; i++){
scanf("%c", &input);

You may want to convert the character into a number:
input = atoi(input);
}
for(i=0; i<10; i++) {
index = P10;
P10_out = input[index-1];
printf("P10_out = %d\n", P10_out);

Since you didn't convert the character into a number,
this will print out the numeric value of the character.
So if I entered an ASCII '0' then this will print
out the value of ASCII '0' which is 0x30 or 48.


--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.comeaucomputing.com/learn/faq/
Other sites:
http://www.josuttis.com -- C++ STL Library book
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,070
Latest member
BiogenixGummies

Latest Threads

Top