| | |
Strings in array [I NEED HELP] C lang.
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Apr 2006
Posts: 1
Reputation:
Solved Threads: 0
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
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
•
•
Join Date: Jul 2005
Posts: 1,741
Reputation:
Solved Threads: 281
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.
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.
![]() |
Similar Threads
- Array (C++)
- Array required, but java.lang.String and java.util.Vector found (Java)
- array required, but java.lang.String found and java.util.Vector found? (Community Introductions)
- array required, but java.lang.String found (Java)
Other Threads in the C Forum
- Previous Thread: Read in a string from a text file
- Next Thread: Robot with GLUT?
| Thread Tools | Search this Thread |
Tag cloud for C
adobe ansi api array arrays bash binarysearch centimeter char convert copyanyfile copypdffile cprogramme createcopyoffile createprocess() csyntax directory dynamic fflush file fork frequency getlasterror givemetehcodez global graphics gtkgcurlcompiling hardware highest homework i/o ide inches infiniteloop initialization interest kilometer km lazy linked linkedlist linux linuxsegmentationfault list locate logical_drives match matrix meter microsoft motherboard multi mysql open opendocumentformat opensource openwebfoundation owf pattern pdf performance pointer pointers posix power problem probleminc program programming pyramidusingturboccodes read recursion recv repetition scanf scheduling segmentationfault send shape single socketprograming socketprogramming spoonfeeding stack standard strchr string strings structures suggestions system systemcall test testautomation unix user voidmain() wab win32api windows.h






