Conversion of contents of an array

September 9, 2010 at 11:53:58
Specs: Linux i686
Hi guys
I need to alter the contents of an integer array which currently contains integers like 1,3,7,1,7,9, etc to be replaced by char type like a,c,g,a,g,i etc, where numbers can be replaced by a unique char alphabet.
Can anybody help?
Thanks in advance.

See More: Conversion of contents of an array

Report •

September 10, 2010 at 11:00:59
not sure if it's what you're after, but maybe

char *s = "abcd";
int arr[4] = { 0 },
n = s[arr[0]];

arr[2] = 'B';

the above would result in the letter's code - 97, 98, 99, 100, etc.

If you need to keep the 0,1, 2, 3 sort of thing, subtract 'A'; arr[1] = s[arr[0]] - 'A' be wary of the number system used though.

I have no aspiration for preaching. ;-)

Report •

September 10, 2010 at 11:25:36
Ok, I actually solved that using a for loop and a couple of ifs and else ifs. But I have a new problem now, earlier I was taking the input from the user in the form of single character but I now want the user to enter words or sentences (using character arrays). But I don't want to predefine the array width as it doesn't terminate before making the user input all the 500 values(As in this case). I want it to terminate with the user pressing an enter or something. Is that possible with all the conversion protocol mentioned below?

Here's a sample code to make you understand what I'm trying to say:

//sample code
void main()
int count=0,i,temp;
char character, input[500];
printf("Enter the character\n");
for (i=0;i<500;i++)
if (temp>1)
if (input[i]==0)
else if (input[i]==1)

if (temp==0)

else if (temp==1)

printf("The equivalent of character %c is ",character);

for (i=count;i>=0;i--)

Report •
Related Solutions

Ask Question