089. 문자가 알파벳인지 검사하기(isalpha)089. 문자가 알파벳인지 검사하기(isalpha)

Posted at 2011. 2. 12. 01:10 | Posted in Computer/초보자를 위한 C 언어 300제
#include <stdio.h>
#include <ctype.h>

void main( void )
{
	char *string = "Cat 1 Car 2 Cow 3,...";
	char buffer[100] = {0,};
	int cnt = 0;

	while( *string )
	{
		if(isalpha( *string ))
		{
			buffer[cnt++] = *string;
		}

		string++;
	}

	puts( buffer );
}
//

088. 실수를 문자열로 변환하기 3(gcvt)088. 실수를 문자열로 변환하기 3(gcvt)

Posted at 2011. 2. 12. 01:08 | Posted in Computer/초보자를 위한 C 언어 300제
#include <stdio.h>
#include <stdlib.h>

void main( void )
{
	double value;
	char buffer[100];

	value = 3.14e10;
	gcvt( value, 3, buffer );

	printf( "변환된 문자열은 %s입니다.\n", buffer );

	value = -3.14e10;
	gcvt( value, 3, buffer );

	printf( "변환된 문자열은 %s입니다.\n", buffer );
}
//

087. 실수를 문자열로 변환하기 2(ecvt)087. 실수를 문자열로 변환하기 2(ecvt)

Posted at 2011. 2. 12. 01:05 | Posted in Computer/초보자를 위한 C 언어 300제
#include <stdio.h>
#include <stdlib.h>

void main( void )
{
	double value;
	char *pstr;
	int dec, sign;

	value = 3.14e10;
	pstr = ecvt( value, 3, &dec, &sign );

	printf( "변환된 문자열은 %s입니다.\n", pstr );
	printf( "소수점의 위치는 %d, 부호는 %d입니다.\n", dec, sign );

	value = -3.14e10;
	pstr = ecvt( value, 3, &dec, &sign );

	printf( "변환된 문자열은 %s입니다.\n", pstr );
	printf( "소수점의 위치는 %d, 부호는 %d입니다.\n", dec, sign );
}
//

086. 실수를 문자열로 변환하기 1(fcvt)086. 실수를 문자열로 변환하기 1(fcvt)

Posted at 2011. 2. 12. 00:57 | Posted in Computer/초보자를 위한 C 언어 300제
#include <stdio.h>
#include <stdlib.h>

void main( void )
{
	double value;
	char *pstr;
	int dec, sign;

	value = 3.1415926535;
	pstr = fcvt( value, 6, &dec, &sign );

	printf( "변환된 문자열은 %s입니다.\n", pstr );
	printf( "소수점의 위치는 %d, 부호는 %d입니다.\n", dec, sign );

	value = -3.1415926535;
	pstr = fcvt( value, 8, &dec, &sign );
	printf( "변환된 문자열은 %s입니다.\n", pstr );
	printf( "소수점의 위치는 %d, 부호는 %d입니다.\n", dec, sign );
}
//

085. 정수를 문자열로 변환하기 3(ultoa)085. 정수를 문자열로 변환하기 3(ultoa)

Posted at 2011. 2. 12. 00:53 | Posted in Computer/초보자를 위한 C 언어 300제
#include <stdio.h>
#include <stdlib.h>

void main( void )
{
	long value;
	char string[100];
	int radix;

	radix = 16;		// 16진수

	value = 34567;
	ultoa( value, string, radix );
	printf( "변환된 문자열은 %s입니다.\n", string );

	value = 1234567890;
	ultoa( value, string, radix );
	printf( "변환된 문자열은 %s입니다.\n", string );
}
//

084. 정수를 문자열로 변환하기 2(ltoa)084. 정수를 문자열로 변환하기 2(ltoa)

Posted at 2011. 2. 12. 00:51 | Posted in Computer/초보자를 위한 C 언어 300제
#include <stdio.h>
#include <stdlib.h>

void main( void )
{
	long value;
	char string[100];
	int radix;

	radix = 2;		// 2진수

	value = 12345;
	ltoa( value, string, radix );
	printf( "변환된 문자열은 %s입니다.\n", string );

	value = -12345;
	ltoa( value, string, radix );
	printf( "변환된 문자열은 %s입니다.\n", string );
}
//

083. 정수를 문자열로 변환하기 1(itoa)083. 정수를 문자열로 변환하기 1(itoa)

Posted at 2011. 2. 9. 04:33 | Posted in Computer/초보자를 위한 C 언어 300제
#include <stdio.h>
#include <stdlib.h>

void main( void )
{
	int value;
	char string[100];
	int radix;

	radix = 10;

	value = 5;
	itoa( value, string, radix );
	printf( "변환된 문자열은 %s입니다.\n", string );

	value = -12345;
	itoa( value, string, radix );
	printf( "변환된 문자열은 %s입니다.\n", string );
}
//

082. 문자열을 실수로 변환하기 2(strtod)082. 문자열을 실수로 변환하기 2(strtod)

Posted at 2011. 2. 9. 04:31 | Posted in Computer/초보자를 위한 C 언어 300제
#include <stdio.h>
#include <stdlib.h>

void main( void )
{
	char *string = " 1.234E-10";
	char *stop;
	double value;

	value = strtod( string, &stop );

	printf( "%d 개의 문자가 변환되었습니다.\n", stop - string );
	printf( "문자열 [%s]를 숫자로 변환하면 %E입니다.\n", string, value );
}
//

081. 문자열을 실수로 변환하기 1(atof)081. 문자열을 실수로 변환하기 1(atof)

Posted at 2011. 2. 9. 04:29 | Posted in Computer/초보자를 위한 C 언어 300제
#include <stdio.h>
#include <stdlib.h>

void main( void )
{
	char *string1 = "2.1은 1.0보다 큽니다.";
	char *string2 = "1004.5는 천사.오 입니다.";
	char *string3 = "2005년도 입니다.";
	char *string4 = "오늘은 6월 9일입니다.";
	double t1, t2, t3, t4;

	puts( string1 );
	puts( string2 );
	puts( string3 );
	puts( string4 );

	t1 = atof(string1);
	t2 = atof(string2);
	t3 = atof(string3);
	t4 = atof(string4);

	printf( "문자열을 숫자로 변환한 값 : %.1f, %.1f, %.1f, %.1f\n", t1, t2, t3, t4 );
	printf( "총 합은 %.2f입니다.\n", t1 + t2 + t3 + t4 );
}
//

080. 문자열을 정수로 변환하기 4(strtoul)080. 문자열을 정수로 변환하기 4(strtoul)

Posted at 2011. 2. 9. 04:25 | Posted in Computer/초보자를 위한 C 언어 300제
#include <stdio.h>
#include <stdlib.h>

void main( void )
{
	char *string = "11000";
	char *stop;
	int radix;
	unsigned long value;

	radix = 2;

	value = strtoul( string, &stop, radix );

	printf( "%d 개의 문자가 변환되었습니다. \n", stop - string );
	printf( "2진수 %s를 숫자로 변환하면 %u입니다. \n", string, value );
}
//