The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum for Programming
 Forum for Origin C
 Comparing Char arrays to strings
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

kemeyer

39 Posts

Posted - 07/24/2009 :  09:13:51 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Ver.7 and Service Release (Select Help-->About Origin):
Operating System: XP

Hi, I am having trouble with my char arrays.
I am reading in characters into a buffer that have text and numbers that I need for calculation. I am trying to sort through this and put in another char array only the numerics (no letters or special characters). In order to do this, I need to be able to a) tell whether it is a number or not, b) compare the ith position of the buffer char array to the special characters to know when to stop reading in the numbers, and c) cast the collection of numbers to a double or float and assign them to a variable.

I thought for a) I could use is_numeric but it is generating and error for me when I use if(is_numeric(myTempCharArray)==0).

And to compare the special characters such as "/", i tried using memcmp, myTempCharArray.Compare("/") and strcmp. None worked.

Also, one of the characters I have to pick out in order to know when to stop reading numbers is a quotation mark. How in the world do I compare whether myTempCharArray[i] is equal to a quotation mark? When I try to surround the char with quotes, it just sees it an an unfinished string--> """

Thanks,
Katie

Iris_Bai

China
Posts

Posted - 07/26/2009 :  11:47:46 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Katie,

About the usage of is_numeric, please reference to

/** >Mathematical
		Test given string to determine whether it is a numeric string
	Parameters:
		lpcstr = the alpha numeric string to test
		bThousoudSeparatorOK = to decide if thousand's separator can be used, like 1,234,567
		bLeadZeroOK = to decide if 01060 is a number (TRUE) or it should be considered not a number (bLeadZeroOK=FALSE)
	Return: 
		TRUE if given string is numeric, otherwise FALSE.
	Example:
		double	convert_str_to_num(string str)
		{			
			if (is_numeric(str))
				return atof(str);
			else
				return NANUM;
		}
	
*/
BOOL is_numeric(LPCSTR lpcstr, BOOL bThousoudSeparatorOK = TRUE, BOOL bLeadZeroOK = TRUE);


To compare a character if a quotation mark, you can use if( myarr[i] == '\"' )

Iris
Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000