UOMOP

strcpy, strcat, strcmp 본문

Summary/C(++)

strcpy, strcat, strcmp

Happy PinGu 2022. 1. 31. 23:33
#include <stdio.h>
#include <string.h>
#define _CRT_SECURE_NO_WARNINGS
#pragma warning(disable:4996)

int main() {

	char str1[] = "hello";
	char str2[100];

	strcpy(str2, str1);
	printf("%s\n\n", str2);

	////////////////////////////////

	char str3[20] = "hello ";

	strcat(str3, "world!");
	printf("%s\n\n", str3);

	/////////////////////////////////

	char str4[] = "sample";
	char str5[] = "simple";

	int cmp = strcmp(str4, str5);
	int cmp_1 = strcmp(str4, str4);
	int cmp_2 = strcmp(str5, str4);

	printf("strcmp(str4, str5) : %d\n", cmp);
	printf("strcmp(str4, str4) : %d\n", cmp_1);
	printf("strcmp(str5, str4) : %d\n", cmp_2);

}

'Summary > C(++)' 카테고리의 다른 글

포인터와 문자열의 관계  (0) 2022.02.01
포인터, 이중 포인터  (0) 2022.01.31
문자열 길이 찾기  (0) 2022.01.31
do, while  (0) 2022.01.31
switch, break, goto  (0) 2022.01.31
Comments