Jump to content
  • Advertisement
Sign in to follow this  
Spintwo

*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.

If you intended to correct an error in the post then please contact us.

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;
				//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);
}




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 this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by Charles Hwang
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!!


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 this post


Link to post
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 this post


Link to post
Share on other sites
Quote:
Original post by Charles Hwang
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.


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

-me

Share this post


Link to post
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 400
char 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 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;
//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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 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(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 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;
//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 this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!