Click here to Skip to main content
15,888,461 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need some help in Identifying the string. I have incoming string like this
*H1999999#
it can vary from
*H1000000#~*H1999999#
sometimes it is
*H1FINE# or *H1MED#
or any other text in between.Now what I have already done is I have parsed the numeric string and copied the integer value to a buffer. Here is the code for that.
 char H1subbuff[10];
 char head1[4];
 char Initial[2];

 char *ptr;

 memcpy(Initial, &rec[0], 1 );
 Initial[1] = '\0';

 memcpy(head1, &rec[0], 3 );
 head1[3] = '\0';



 if ((strcmp(head1,"*H1") == 0) && (rec[9] == '#'))
  {
     memcpy(H1subbuff, &rec[3], 6 );
     H1subbuff[6] = '\0';

     H1Val = strtol(H1subbuff, &ptr, 10);

     //Display H1VAL
}


Now my query is how can check if the String consist of Number or Alphabet.All I need to check if the Portion between *H1 and # is numeric or Alphabet, if it is a numeric I can use
strtol()
to copy the int value into an buffer. How can I copy the alphabet or text into an buffer?

Note :- The above two string doesn't have same string length.

What I have tried:

I have tried to copy numeric values to a buffer.
Posted
Updated 4-Aug-16 6:49am

1 solution

Use a pointer to skip the prefix alphabetic characters, then use strtol[^] to convert the number to a long value. The endptr variable will then point to the first non-numeric character, allowing you to parse further. Something like:
C++
char* strData = "*H1999999#";
char* strNum = strData + 2;
char* strEnd = NULL;
long lValue = strtol(strNum, &strEnd, 10);
// strEnd will now point to the # character.
 
Share this answer
 
Comments
Member 12670328 4-Aug-16 12:59pm    
How can check if string consist of numeric value or alpahabet?
Richard MacCutchan 4-Aug-16 13:02pm    
use one of the isXXX functions as described at https://msdn.microsoft.com/en-us/library/4yc6feha.aspx.
CPallini 5-Aug-16 3:03am    
5.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900