Strings in array [I NEED HELP] C lang.

Reply

Join Date: Apr 2006
Posts: 1
Reputation: gminis3 is an unknown quantity at this point 
Solved Threads: 0
gminis3 gminis3 is offline Offline
Newbie Poster

Strings in array [I NEED HELP] C lang.

 
0
  #1
Apr 14th, 2006
Im a beginner in C language and I have a problem with strings in array mostly.

Question : User is required to input ID number, which consists of 7 characters. First 2 characters have to be Alphabets and the last 5 will be numbers. Example, AB12345

Task : Error checking for the input, ensure that that first 2 characters have to be alpha and numbers for the rest of the chars.

Problem : How do I separate every single characters and do error checking??

Desperately need help on this


Thanks
Reply With Quote Quick reply to this message  
Join Date: Feb 2005
Posts: 466
Reputation: winbatch is on a distinguished road 
Solved Threads: 18
winbatch's Avatar
winbatch winbatch is offline Offline
Posting Pro in Training

Re: Strings in array [I NEED HELP] C lang.

 
1
  #2
Apr 14th, 2006
Show us the code where you are requesting and accepting the string to begin with, then we'll show you how to modify it for the error checking.
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 1,676
Reputation: Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all 
Solved Threads: 262
Lerner Lerner is offline Offline
Posting Virtuoso

Re: Strings in array [I NEED HELP] C lang.

 
0
  #3
Apr 14th, 2006
an array is a collection of elements of the same type. a C type string is an array of type char where the last char is a null char.

Each element in an array can be accessed individually using the [] operator and an index which is an integer representing the location of the desired element within the array. Array indexes are zero based meaning the first element has index 0, the second element has index 1, etc.

Cstrings can be analyzed using a loop checking each element until you find the null terminating char, and then stopping. Or you can determine the length of the string using the strlen() function stopping when the index is the same value as the length.

For each char you can evaluate using a series of if/elses to see if it is an alphabetical char or you can use isalpha() to see if it is a char. Likewise you can test each char to see if it is a digit by using a series of if/elses or you can use the isdigit() function.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC