You are here:

C++/how to verify a few group of number with alphabets

Advertisement


Question
dear sir,
        i facing problem in writing program now.
i just a beginer and now try to use switch of() write a program which enable me to get a group of information when i enter its name.
 example, i save a group of information under this name"B123",and another group of information in "C234".  when i use switch of() , it can't detect the "B123" and "C234" because switch off can only detect number.

  i try to use compare string but it can only detect one group of information,so not suitable for me because i have a lot of information need to group in.  

  can u teach me  a method to solve this problem?
i only know the very basic method like if else,for,switch of etc. hope u can give me reply soon. thks a lot  

Answer
kelvin lee , Thank you for your question.

I believe you want to compare character strings. A character string is an array of 'char' data type values. A 'char' is an 8-bit signed number that represents a printed character.

To compare two character strings, use the 'strcmp' function.

Here is a code sample:

if (!strcmp(GivenString, "B123"))
  HandleB123();
else if (!strcmp(GivenString, "C234"))
  HandleC234();

David Spector

C++

All Answers


Answers by Expert:


Ask Experts

Volunteer


David Spector

Expertise

Highly knowledgeable in the C++ language, Visual C++ (MSVC), Windows API, documentation and other quality-assurance techniques, and debugging. Knowledgeable in MFC, COM, GUI design, and object-oriented design.

Experience

I have been a software engineer since 1965. I have been published. My specializations have been: biomedical programming, compiler implementation, and many kinds of Windows programming. I don't do Databases or other business-oriented stuff.

Publications
Windows?/DOS Developer's Journal, ACM SIGPLAN Notices, and Computer Science Press.

Education/Credentials
ICCP Systems Programming Certification
Master's degree equivalent in Computer Science

©2016 About.com. All rights reserved.