Public Group

# *problems/questions.

This topic is 5143 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

/*convets user inputted DNA to in the end, convert to final tRNA.*/
#include <iostream>
using namespace std;
#include <conio.h>

char *entire_dna[400]; //limit entry to 400
char *entire_mrna[400];
char *entire_trna[400];
int dna_array_bounds=0;
int max_dab;

//recieve char
//return a char
char dna_input()
{
char singledna;
cin >> singledna;
return(singledna);
}

char copy(char *array1, char *array2) //array1 is the copy source, 2 is copy to be made
{
for(int x=0;x<max_dab;++x)
{
array2[x]=array1[x];
}
return(*array2);
}
//function to check that code is working
void checkdna()
{
for(int i=0;i<max_dab;++i)
cout << entire_dna << " ";
}

int main()
{
cout << "Enter values of a,g,t,c or d anything else\n\n";
//recieve DNA values from user
while(1)
{
//firststep: writes the DNA;
char userinput=dna_input();
if(userinput!='d' && dna_array_bounds<400)
{
//invalid entry check
if(userinput=='a' || userinput=='g' || userinput=='t' || userinput=='c')
{
entire_dna[dna_array_bounds]=&userinput;
++dna_array_bounds;
}
}
else
break;

}
max_dab=dna_array_bounds; //sets how many dna "stuff" are set
copy(&entire_dna, &entire_mrna);
//We recieved the DNA input and now we need to
//chnage it to mRNA
//Conversioin: A-U,T-A,C-G
for(int j=0;j<max_dab;++j)
{
//need to dereference the pointer.
char mrna=*entire_dna[j];
switch(mrna)
{
case 'a': *entire_dna[j]='u';
break;
case 't': *entire_dna[j]='a';
break;
case 'c': *entire_dna[j]='g';
break;
case 'g': *entire_dna[j]='c';
break;
}
}

checkdna();
getch();
return(0);
}


I need a fix for this code urgently for results FROM the program. I'm planning on reading the c++ book tomorrow and refreshing references and pointers but anyonewith a fix will be greatly appreciated!! This s the error I get: --------------------Configuration: dna - Win32 Debug-------------------- Compiling... main.cpp C:\Program Files\Microsoft Visual Studio\MyProjects\dna\main.cpp(59) : error C2664: 'copy' : cannot convert parameter 1 from 'char *(*)[400]' to 'char *' Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast Error executing cl.exe. dna.exe - 1 error(s), 0 warning(s) And moer than likely, I used * or & incorrectly. [Edited by - Charles Hwang on September 13, 2004 10:40:52 PM]

##### Share on other sites
Quote:
 Original post by Charles HwangI need a fix for this code urgently for results FROM the program. I'm planning on reading the c++ book tomorrow and refreshing references and pointers but anyonewith a fix will be greatly appreciated!!

if you need a fix you also need to tell us how it's broken...in detail.

but in the meantime these are all wrong:

char *entire_dna[400]; //limit entry to 400
char *entire_mrna[400];
char *entire_trna[400];

they should be:

char entire_dna[400]; //limit entry to 400
char entire_mrna[400];
char entire_trna[400];

-me

##### Share on other sites
ok..then how do i make a pointer out of it? I'm going to be sending stuff from funciotn to main and stuff. i can't do that without a pointer.

##### Share on other sites
Quote:
 Original post by Charles Hwangok..then how do i make a pointer out of it? I'm going to be sending stuff from funciotn to main and stuff. i can't do that without a pointer.

it's already a pointer. an array variable is a pointer to a sequantial series of other variables in memory.

-me

##### Share on other sites
/*convets user inputted DNA to in the end, convert to final tRNA.*/#include <iostream>using namespace std;#include <conio.h>char aentire_dna[400]; //limit entry to 400char aentire_mrna[400];char aentire_trna[400];char *entire_dna=&aentire_dna;char *entire_mrna=&aentire_mrna;char *entire_trna=&aentire_trna;int dna_array_bounds=0;int max_dab;//recieve char//return a charchar dna_input(){	char singledna;	cin >> singledna;	return(singledna);}char copy(char *array1, char *array2) //array1 is the copy source, 2 is copy to be made{	for(int x=0;x<max_dab;++x)	{		array2[x]=array1[x];	}	return(*array2);}//function to check that code is workingvoid checkdna(){	for(int i=0;i<max_dab;++i)		cout << entire_dna << " ";}int main(){	cout << "Enter values of a,g,t,c or d anything else\n\n";	//recieve DNA values from user	while(1)	{		//firststep: writes the DNA;		char userinput=dna_input();		if(userinput!='d' && dna_array_bounds<400)		{			//invalid entry check			if(userinput=='a' || userinput=='g' || userinput=='t' || userinput=='c')			{				entire_dna[dna_array_bounds]=&userinput;				//increment to read everything.				++dna_array_bounds;			}		}		else			break;	}	max_dab=dna_array_bounds; //sets how many dna "stuff" are set	copy(&entire_dna, &entire_mrna);	//We recieved the DNA input and now we need to	//chnage it to mRNA	//Conversioin: A-U,T-A,C-G	for(int j=0;j<max_dab;++j)	{		//need to dereference the pointer.		char mrna=*entire_dna[j];		switch(mrna)		{		case 'a': *entire_dna[j]='u';			break;		case 't': *entire_dna[j]='a';			break;		case 'c': *entire_dna[j]='g';			break;		case 'g': *entire_dna[j]='c';			break;		}	}	checkdna();	getch();	return(0);}

/me cries...more errors

##### Share on other sites
couple of changes to get it to compile / work:

- remove the * from the first 3 'char' defines as 'Palidine' mentions. you want them to be character array's, so the [400] does that.
- in the 'copy' function, if you're not using the return just change it to 'void'

- the line:
entire_dna[dna_array_bounds]=&userinput;
should be
entire_dna[dna_array_bounds]=userinput;

- the line:
copy(&entire_dna, &entire_mrna);
should be
copy(entire_dna, entire_mrna);

- the line:
char mrna=*entire_dna[j];
should be
char mrna=entire_dna[j];

- change the 4:
case 'a': *entire_dna[j]='u';
lines to
case 'a': entire_dna[j]='u';
(remove the *)

after these changes I get the following output:
aaagggd
u u u c c c

hope this helps.

##### Share on other sites
as a follow up, just read any good C++ book on pointers, specifically around string manipulation and passing character arrays around. you have the right intentions, just some assignment confusions.

##### Share on other sites
An array name is functionally equivalent to a pointer. There are differences - obtaining the length of an array name should give you the length of the array, not the size of the pointer, for instance, but generally speaking they are equivalent.

So to pass the entire array to a function simply use entire_dna. In your function you can then use it to access the contents of the array.

void somefunc(char arr[])
{
...
}

void main()
{
somefunc(entire_dna);
}

##### Share on other sites
Well Now i've got this, only one error left:

/*convets user inputted DNA to in the end, convert to final tRNA.*/#include <iostream>using namespace std;#include <conio.h>char entire_dna[400]; //limit entry to 400char entire_mrna[400];char entire_trna[400];int dna_array_bounds=0;int max_dab;//recieve char//return a charchar dna_input(){	char singledna;	cin >> singledna;	return(singledna);}char copy(const char *&array1, char *&array2) //array1 is the copy source, 2 is copy to be made{	for(int x=0;x<max_dab;++x)	{		array2[x]=array1[x];	}	return(*array2);}//function to check that code is workingvoid checkdna(){	for(int i=0;i<max_dab;++i)		cout << entire_dna << " ";}int main(){	cout << "Enter values of a,g,t,c or d anything else\n\n";	//recieve DNA values from user	while(1)	{		//firststep: writes the DNA;		char userinput=dna_input();		if(userinput!='d' && dna_array_bounds<400)		{			//invalid entry check			if(userinput=='a' || userinput=='g' || userinput=='t' || userinput=='c')			{				entire_dna[dna_array_bounds]=userinput;				//increment to read everything.				++dna_array_bounds;			}		}		else			break;	}	max_dab=dna_array_bounds; //sets how many dna "stuff" are set	copy(entire_dna, entire_mrna);	//We recieved the DNA input and now we need to	//chnage it to mRNA	//Conversioin: A-U,T-A,C-G	for(int j=0;j<max_dab;++j)	{		//need to dereference the pointer.		char mrna=entire_dna[j];		switch(mrna)		{		case 'a': entire_dna[j]='u';			break;		case 't': entire_dna[j]='a';			break;		case 'c': entire_dna[j]='g';			break;		case 'g': entire_dna[j]='c';			break;		}	}	checkdna();	getch();	return(0);}

And i get ONE error:

--------------------Configuration: dna - Win32 Debug--------------------
Compiling...
main.cpp
C:\Program Files\Microsoft Visual Studio\MyProjects\dna\main.cpp(59) : error C2664: 'copy' : cannot convert parameter 1 from 'char [400]' to 'const char *& '
A reference that is not to 'const' cannot be bound to a non-lvalue
Error executing cl.exe.

dna.exe - 1 error(s), 0 warning(s)

Any ideas?

##### Share on other sites
Well...I figured it out for myself, with a little help. Thanks guys.

1. 1
2. 2
Rutin
18
3. 3
4. 4
5. 5

• 11
• 14
• 9
• 9
• 9
• ### Forum Statistics

• Total Topics
632924
• Total Posts
3009232
• ### Who's Online (See full list)

There are no registered users currently online

×