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
 All Forums
 Origin Forum for Programming
 Forum for Origin C
 Comparing Char arrays to strings

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Screensize:
UserName:
Password:
Anti-Spam Code:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkUpload FileInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
kemeyer Posted - 07/24/2009 : 09:13:51 AM
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
1   L A T E S T    R E P L I E S    (Newest First)
Iris_Bai Posted - 07/26/2009 : 11:47:46 PM
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

The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000