User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C section within the Software Development category of DaniWeb, a massive community of 456,586 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,624 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C advertiser: Programming Forums
Views: 1031 | Replies: 3
Reply
Join Date: Nov 2007
Posts: 5
Reputation: BensonRoss is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
BensonRoss BensonRoss is offline Offline
Newbie Poster

Help Determining Invalid Characters in a String??

  #1  
Nov 4th, 2007
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
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Dec 2005
Posts: 3,834
Reputation: Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of 
Rep Power: 23
Solved Threads: 436
Colleague
Salem's Avatar
Salem Salem is offline Offline
banned

Re: Determining Invalid Characters in a String??

  #2  
Nov 4th, 2007
Something simple like a for loop to check each character in turn perhaps?
Reply With Quote  
Join Date: Oct 2007
Location: Cherry Hill, NJ
Posts: 1,878
Reputation: Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold 
Rep Power: 13
Solved Threads: 193
Featured Poster
Duoas's Avatar
Duoas Duoas is offline Offline
Posting Virtuoso

Re: Determining Invalid Characters in a String??

  #3  
Nov 4th, 2007
Or you could just use the strspn() function:
if (strspn( dnaStr, "AaTtCcGg" ) < strlen( dnaStr )) puts( "error in DNA" );
Reply With Quote  
Join Date: Dec 2006
Posts: 1,569
Reputation: Aia is a splendid one to behold Aia is a splendid one to behold Aia is a splendid one to behold Aia is a splendid one to behold Aia is a splendid one to behold Aia is a splendid one to behold Aia is a splendid one to behold 
Rep Power: 12
Solved Threads: 114
Aia's Avatar
Aia Aia is offline Offline
Posting Virtuoso

Re: Determining Invalid Characters in a String??

  #4  
Nov 4th, 2007
Originally Posted by Duoas View Post
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().
At the very moment that I find myself in the side of the mayority, I will know that I need to re-think my ideas. ~ In my book.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb C Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the C Forum

All times are GMT -4. The time now is 6:34 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC