336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

목표 : 

1. Hello World 를 출력하는 Console을 만들어 봅니다. 


소스 코드 : Program.cs 

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;


namespace _01_HelloWorld

{

    class Program

    {

        static void Main(string[] args)

        {

            Console.WriteLine("Hello World");

        }

    }

}



결과


'Programing C# > C# Basic grammar' 카테고리의 다른 글

06 다차원 배열  (0) 2019.05.11
05 배열  (0) 2018.11.06
04 문자와 문자열  (0) 2018.02.24
03 기본변수들 출력  (0) 2018.02.19
02 기본 변수 출력  (0) 2018.02.18
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

개념 :

1. time.h 에 포함되어 있는 ctime 함수를 사용합니다. 

2. 원형 : char* ctime(const time_t *timer)


소스 코드 : main.c

//

//  main.c

//  128

//

//  Created by 이준모 on 2018. 2. 8..

//  Copyright © 2018년 이준모. All rights reserved.

//


#include <stdio.h>

#include <time.h>

int main(int argc, const char * argv[])

{

    // insert code here...

    time_t now;

    time(&now);

    

    printf("현재 날짜 및 시간 : %s", ctime(&now));

    return 0;

}


결과:


336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

개념 :


1. 원형 : void _ftime(struct _timeb *timeptr);


2. 구조체 : 

struct _timeb

{

time_t    time;          //time_t

unsigned    short;    millitm // 1/1000초

short    timezone; //세계 표준시와 현지와의 분수의 차이

short    dstflag;    //써머타임 적용 시 0이 아닌 값, 그밖에는 0 

};




소스코드 : main.c


#include <stdio.h>

#include <time.h>

#include <sys/timeb.h>

#include <memory.h>

int main(int argc, const char * argv[])

{

    struct timeb tb; // _timeb use windows 

    struct tm t;

    

    ftime(&tb); // _ftime use windows

    

    t= *localtime(&tb.time);

    

    printf("현재 날짜 및 시간 : %4d. %d. %d. %d. %d. %d. %d \n",t.tm_year+1900, t.tm_mon+1, t.tm_mday, t.tm_hour, t.tm_min, t. tm_sec, tb.millitm);

    return 0;

}




결과:




336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

개념 : 


1. 원형: struct tm* localtime(const time_t *time);


2. 파라메터 *time을 기준으로 struct tm* 으로 반환하여줍니다.


3. struct tm

#ifndef _TM_DEFINED

struct tm {

        int tm_sec;     /* seconds after the minute - [0,59] */

        int tm_min;     /* minutes after the hour - [0,59] */

        int tm_hour;    /* hours since midnight - [0,23] */

        int tm_mday;    /* day of the month - [1,31] */

        int tm_mon;     /* months since January - [0,11] */

        int tm_year;    /* years since 1900 */

        int tm_wday;    /* days since Sunday - [0,6] */

        int tm_yday;    /* days since January 1 - [0,365] */

        int tm_isdst;   /* daylight savings time flag */

        };

#define _TM_DEFINED




소스코드 : main.c


#include<stdio.h>

#include<time.h>



int main(void)

{

time_t now;

struct tm t;


time(&now);


t = *localtime(&now);


printf("%d . %d . %d        %d : %d : %d \n", t.tm_year + 1900, t.tm_mon + 1, t.tm_mday, t.tm_hour, t.tm_min, t.tm_sec);


system("pause");

return 0;

}





결과:


336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

방법 1. 


#define _CRT_SECURE_NO_WARNINGS 을 추가 해준다.



방법 2. 


프로젝트 속성 > C/C++ > 전처리기 > 전처리기 정의 (편집 선택) > _CRT_SECURE_NO_WARNINGS 을 추가 한다.



336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

개념 : 


1. time.h에 포함되어 있다.


2. 세계표준시 1970년 1월 1일 0시 0초 부터 현재까지 경과된 초를 알려준다.


3. 원형 :  time_t time( time_t *timer);


4. time_t형은 내부적으로 long형으로 선언되어 있다.




소스코드 : main.c


#include<stdio.h>

#include<time.h>


int main(void)

{

time_t now;


time(&now);


printf("국제 표준시간 기준으로 1970년 1월 1일 부터 현재까지 경과된 초 : %d \n", now);


system("pause");

return 0;

}





결과 : 



336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

개념 :


1. direct.h 포함되어 있음


2. 원형 : 

- 작업중 드라이버 구하기 : int _getdrive(void);

- 작업중인 드라이버 변경 : int _chdrive(int drive);


3.  A dirve는 1번이며 순서대로 번호가 된다. 따라서 Z dirve 26번이 된다.


4. 드라이버 변경시 성공은 0 실패는 -1을 리턴한다.





소스코드 : main.c


#include<stdio.h>

#include<direct.h>


int main(void)

{

int CurrentDrive = 0;

int ChangeDrive = 4; // A = 1 , B = 2, C = 3, D = 4


CurrentDrive = _getdrive();

printf("현재  %c dirve에서 작업중  입니다.\n", ('A' - 1) + CurrentDrive);

printf("changed %c drive", ('A' - 1) + ChangeDrive);


if (_chdrive(ChangeDrive) == 0)

{

puts("change success");

CurrentDrive = _getdrive();

printf("현재  %c dirve에서 작업중  입니다.\n", ('A' - 1) + CurrentDrive);

}

else

{

perror("작업중인 드라이버 변경 실패");

}


system("pause");

return 0;

}





결과:




336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

개념 : 


1. direct.h 에 포함되어 있습니다.


2. 원형 : 

 -현재 작업중 디렉터리 : char* _getcwd(char* buffer, int maxlen);

-디렉터리 변경 : int _chdir(char* buffer);  // return -1 error, 0 success




소스코드 : main.c


#include <stdio.h>

#include <stdlib.h>//_MAX_PATH 사용하기 위해 선언

#include <direct.h>


int main(void)

{

char currentPath[_MAX_PATH];

const char *pChangePath = "C:\\Users\\junmo\\Desktop\\300\\123\\ChangeDir";


_getcwd(currentPath, _MAX_PATH);


puts(currentPath);

puts("change Path");

_chdir(pChangePath);

_getcwd(currentPath, _MAX_PATH);

puts(currentPath);


system("pause");


return 0;

}




결과 :



336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

개념 : 

1. direct.h 에 포함되어 있습니다.


2. 원형 

- 디렉터리 생성 : int _mkdir(const char* dirname);

- 디렉터리 삭제 : int _rmdir(const char* dirname);


3. 에러시 -1을 반환합니다.




소스코드 : main.c

#include<stdio.h>

#include<direct.h>



int main(void)

{

//생성

const char* pPathDir = "C:\\Users\\junmo\\Desktop\\300\\122\\TestDir";


if (_mkdir(pPathDir) == -1)

{

perror("Dir 생성 실패");

}

else

{

puts("Dir 생성 성공");

}


// 삭제

if (_rmdir(pPathDir) == -1)

{

perror("Dir 삭제 실패");

}

else

{

puts("Dir 삭제 성공");

}



system("pause");

return 0;

}





결과 : 




336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

개념 :


1. stdio.h 에 포함 되어 있습니다.


2. 파일을 삭제합니다.


3. 원형 : int remove(const char *path);





소스코드 : main.c


#include<stdio.h>



int main(void)

{

char *filePath = "C:\\Users\\junmo\\Desktop\\300\\121\\file.txt";

FILE *fp = NULL;


fopen_s(&fp, filePath, "w+");//파일을 생성


if (fp != NULL)//파일 생성되었다면

{

fclose(fp);//파일 닫기

}


//속성 값 변경

if (remove(filePath) != 0)

{

perror("삭제 실패");

}

else

{

puts("삭제 성공");

}



system("pause");

return 0;

}







결과 :



+ Recent posts