I am taking a programming course, and since we have not been introduced to string functions (puts(), gets(), etc) I need to take some input from the user using scanf.
The assignment is to read a DNA sequence, storing it in a char array. The array must be 512 characters, and accept only the characters 'G', 'A', 'T', and 'C'. Space, tab, and enter should be ignored. Additionally, the user enters 'X' to end the DNA sequence. If the user enters any character other than those allowed, the program must return -1 on exit (an error).
The input from the user would look something like: "GATCACTACX"
My problem is that I cannot seem to assign any values to my array. My code so far (just for reading the string) looks like this:
for ( x = 0; x < 512; x++ ) {
scanf("%c", &sequencetemp);
if ((sequencetemp=='A') || (sequencetemp=='T') || (sequencetemp=='G') || (sequencetemp=='C')){
sequence[x] = sequencetemp;
} else if (sequencetemp=='X'){
break;
}else{}
}
Upon testing, my char array is just full of random junk characters. Is there something I am doing wrong? Does anyone have a better solution? Can I do this assignment without using string functions?
Any help would be appreciated.