728x90
반응형
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int DEFAULT = 6;

int main(void)
{
	char* test_1 = NULL;

	printf("%s\n", test_1);	// (null)

	char* test_2 = "Hello World";

	printf("%s\n", test_2);	// Hello World

	char* test_3 = "X";

	printf("%s\n", test_3);	// X

	char* test_4 = 'Y';

	printf("%c\n", test_4); // Y // Code Error : C6274

	/****************************************************/

	// Access Index //

	printf("%c\n", test_2[0]);	// H
	printf("%c\n", test_2[DEFAULT]);	// W
	
	// Iteration : for //
	puts("FOR");
	for (int i = 0; i < strlen(test_2); i++)
	{
		printf("%c ", test_2[i]);	// H e l l o   W o r l d
	}
	puts("\n");

	// Iteration : while //
	puts("WHILE");
	int i = 0;
	while (test_2[i] != NULL)
	{
		printf("%c ", test_2[i]);	// H e l l o   W o r l d
		i++;
	}
	printf("\n\n");
	
	// String copy //
	puts("String copy: ");
	char* test_5;
	
	//test_5 = &test_2;	// ERROR
	//strcpy(test_5, test_2);	//ERROR
	test_5 = test_2; // CORRECT : just transfer address

	printf("%s\n", test_5);

	printf("\n\n\n");

	/////////////////////////////////////////
	printf("Practice : \n");

	char* ox = "o x o x x x x o F";
	char xo[] = "o x o x x x x o F";

	printf("%c\n", ox[0]);	// print : o
	printf("%c\n", xo[0]);	// print : o

	int j = 0;
	while (ox[j] != NULL)
	{
		printf("%c ", ox[j]);
		j++;
	}
	printf("\n");
	printf("===== LINE =====\n");

	int k = 0;
	while (xo[k] != NULL)
	{
		printf("%c ", xo[k]);
		k++;
	}


	//char* p = NULL;

	// What the hell is difference between pointer string and array string?!
	// strtok (char *_string, const char *_delimiters);
	
	//p = strtok(ox, " ");	// NO PRINT
	//p = strtok(xo, " ");	// PRINT 'o'
	//printf("%s", p);






	return 0;
}
728x90
반응형

+ Recent posts