943,948 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 1622
  • C RSS
Apr 14th, 2006
0

Strings in array [I NEED HELP] C lang.

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
gminis3 is offline Offline
1 posts
since Apr 2006
Apr 14th, 2006
1

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

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.
Reputation Points: 68
Solved Threads: 18
Posting Pro in Training
winbatch is offline Offline
466 posts
since Feb 2005
Apr 14th, 2006
0

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

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.
Reputation Points: 718
Solved Threads: 373
Nearly a Posting Maven
Lerner is offline Offline
2,253 posts
since Jul 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: Read in a string from a text file
Next Thread in C Forum Timeline: Robot with GLUT?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC