I am new to the world of C but am enthusiastic nonetheless, so pardon me if this appears to be a particularly basic question...

I am attempting to write a program that uses DNA strands.. which consist of A,T,C,and G characters...

The user is prompted to input a DNA strand.

After they have input the string of a certain length I want to use a user defined function to check the string and ensure the fact that it doesn't contain any letters that are not A,T,C, or G. If it does contain an invalid character I want to alert the User... If it does not contain any characters other than A,T,C, or G then there will be no problem and the program will continue...

any help regarding this would be greatly appreciated.

David

Recommended Answers

All 3 Replies

Something simple like a for loop to check each character in turn perhaps?

Or you could just use the strspn() function: if (strspn( dnaStr, "AaTtCcGg" ) < strlen( dnaStr )) puts( "error in DNA" );

commented: Aye +4

Or you could just use the strspn() function: if (strspn( dnaStr, "AaTtCcGg" ) < strlen( dnaStr )) puts( "error in DNA" );

@BensonRoss, make sure you include <string.h> for strspn() and strlen().

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.