Пример #1
0
float strtoFloat(char s[])
{
	int i = 0, j, intValue, intResult = 0, floatResult = 0, sign = 1, dotIndex;
	float finalResult;
	
	if(s[0] == '-')
	{
		++i;
		sign *= -1;
	}
	
    dotIndex = findDot(s);
//    printf("%i\n", dotIndex);
    
    for(; i<dotIndex && s[i] >= '0' && s[i] <= '9'; ++i)
    {
    	intValue = s[i] - '0';
    	intResult = intResult * 10 + intValue;
	}
	
	for(j=dotIndex+1; s[j] >= '0' && s[j] <= '9'; ++j)
	{   
		intValue = s[j] - '0';
		floatResult = floatResult * 10 + intValue; 
	}
    
	finalResult = (float) intResult + ((float) floatResult / pow(10, j - dotIndex - 1));
	return sign * finalResult;
}
Пример #2
0
/****************************************************************************
DESCRIPTION:
Split a full pathname into components.

HEADER:
pmapi.h

PARAMETERS:
path	- Full path to split
drive	- Drive component for path
dir		- Directory component for path
name	- Filename component for path
ext		- Extension component for path

RETURNS:
Flags indicating what components were parsed.

REMARKS:
Function to split a full pathmame into separate components in the form

	X:\DIR\SUBDIR\NAME.EXT

and splits path into its four components. It then stores those components
in the strings pointed to by drive, dir, name and ext. (Each component is
required but can be a NULL, which means the corresponding component will be
parsed but not stored).

The maximum sizes for these strings are given by the constants PM_MAX_DRIVE
and PM_MAX_PATH. PM_MAX_DRIVE is always 4, and PM_MAX_PATH is usually at
least 256 characters. Under Unix the dir, name and ext components may be
up to the full path in length.

SEE ALSO:
PM_makePath
****************************************************************************/
int PMAPI PM_splitpath(
	const char *path,
	char *drive,
	char *dir,
	char *name,
	char *ext)
{
	char	*p;
	int    	temp,ret;
	char 	buf[PM_MAX_PATH+2];

	/* Set all string to default value zero */
	ret = 0;
	if (drive) 	*drive = 0;
	if (dir) 	*dir = 0;
	if (name) 	*name = 0;
	if (ext)	*ext = 0;

	/* Copy filename into template up to PM_MAX_PATH characters */
	p = buf;
	if ((temp = strlen(path)) > PM_MAX_PATH)
		temp = PM_MAX_PATH;
	*p++ = 0;
	strncpy(p, path, temp);
	*(p += temp) = 0;

	/* Split the filename and fill corresponding nonzero pointers */
	temp = 0;
	for (;;) {
		switch (*--p) {
			case '.':
				if (!temp && (*(p+1) == '\0'))
					temp = findDot(p);
				if ((!temp) && ((ret & PM_HAS_EXTENSION) == 0)) {
					ret |= PM_HAS_EXTENSION;
					safe_strncpy(ext, p, PM_MAX_PATH - 1);
					*p = 0;
					}
				continue;
			case ':':
				if (p != &buf[2])
					continue;
			case '\0':
				if (temp) {
					if (*++p)
						ret |= PM_HAS_DIRECTORY;
					safe_strncpy(dir, p, PM_MAX_PATH - 1);
					*p-- = 0;
					break;
					}
			case '/':
			case '\\':
				if (!temp) {
					temp++;
					if (*++p)
						ret |= PM_HAS_FILENAME;
					safe_strncpy(name, p, PM_MAX_PATH - 1);
					*p-- = 0;
					if (*p == 0 || (*p == ':' && p == &buf[2]))
						break;
					}
				continue;
			case '*':
			case '?':
				if (!temp)
					ret |= PM_HAS_WILDCARDS;
			default:
				continue;
			}
		break;
		}
	if (*p == ':') {
		if (buf[1])
			ret |= PM_HAS_DRIVE;
		safe_strncpy(drive, &buf[1], PM_MAX_DRIVE - 1);
		}
	return ret;
}