#include<stdio.h>
#include<string.h>

void main()
{
 int num[10] = { 1, 2, 3, 4, 5 };
 printf("size:%d, length: %d \n"
  , sizeof(num), sizeof(num) / sizeof(int));
}

 

'Computer Language > c 언어' 카테고리의 다른 글

strlen문자의 길이 sizeof 배열의 크기  (0) 2014.04.10
문자열  (0) 2014.04.10
구조체 선언시 typedef  (0) 2014.04.10
strcmp 활용  (0) 2014.04.10
NULL == '0' == 0  (0) 2014.04.10

 

#include<stdio.h>
#include<string.h>

void main()
{
 char ch1[10] = "abcdef", ch2[10];

 printf("%d, %d \n", strlen(ch1), sizeof(ch1));
 strncpy_s(ch2, sizeof(ch1), ch1, 7);

 puts(ch2);
}

'Computer Language > c 언어' 카테고리의 다른 글

sizeof int형  (0) 2014.04.10
문자열  (0) 2014.04.10
구조체 선언시 typedef  (0) 2014.04.10
strcmp 활용  (0) 2014.04.10
NULL == '0' == 0  (0) 2014.04.10

 

#include<stdio.h>

void main()
{
 char c;
 char ch1[10];

 //puts("abcd"); // 문자열만 출력
 gets_s(ch1, 10);
 puts(ch1);

 c = getchar();
 putchar(c);
}

'Computer Language > c 언어' 카테고리의 다른 글

sizeof int형  (0) 2014.04.10
strlen문자의 길이 sizeof 배열의 크기  (0) 2014.04.10
구조체 선언시 typedef  (0) 2014.04.10
strcmp 활용  (0) 2014.04.10
NULL == '0' == 0  (0) 2014.04.10

typedef int myint;

int와 myint는 같다.

 

typedef struct user
{
 char name[20];
 char phone[20];
}MMr;

 

MMr-> 애얼리싱 (별칭)

'Computer Language > c 언어' 카테고리의 다른 글

strlen문자의 길이 sizeof 배열의 크기  (0) 2014.04.10
문자열  (0) 2014.04.10
strcmp 활용  (0) 2014.04.10
NULL == '0' == 0  (0) 2014.04.10
라이브러리  (0) 2014.04.09

if(!strcmp(*u).name, " "))

 

if(strcmp( (*u).name, "") = 0)

 

boolean true;

if(!true)

'Computer Language > c 언어' 카테고리의 다른 글

문자열  (0) 2014.04.10
구조체 선언시 typedef  (0) 2014.04.10
NULL == '0' == 0  (0) 2014.04.10
라이브러리  (0) 2014.04.09
구조체 배열  (0) 2014.04.09

NULL == '0' == 0

CHAR형 뒤에는 널 값이 들어간다.

'Computer Language > c 언어' 카테고리의 다른 글

구조체 선언시 typedef  (0) 2014.04.10
strcmp 활용  (0) 2014.04.10
라이브러리  (0) 2014.04.09
구조체 배열  (0) 2014.04.09
열거자 에러를 선언시  (0) 2014.04.09

#include<stdio.h>

//1. 문자 길이
int strlen(char* s)
{
 char* temp = s;
 while (*++temp)
  ; /* not thing */

 return temp - s;

}
//2. 문자열 복사. source -> dest
void strcpy(char* dest, char* source)
{
 while (*dest++ = *source++)
  ; /*not thing*/
}

//3. strcmp(char * dest, char* source)
int strcmp(char* dest, char* source)
{
 for (; *dest && *source; dest++, source++){
  ; /* not thing*/
 }
 if (*source - *dest > 0){
  return 1;
 }
 else if (*source - *dest < 0){
  return -1;
 }
 else
  return *source - *dest;
}

// ASCII TO INTEGER 4. atoi(char *) : 문자 -> 숫자.
int atoi(char* source){
 int num = 0;
 for (; *source; source++)
 {
  num = 10 * num + *source - '0';
 }
 return num;
}
//5. integer to ascii : 숫자 -> 문자
void itoa(int num, char* src)

 //거꾸로 복사하고
 //num = 12345;
 char* temp = src;
 while (num > 0)
 {
  char c = num % 10 + '0';
  *temp++ = c;

  num = num / 10;
 }

 printf("text: %s \n", src);

 //리버스.
 //src = 54321
 //14325 -> 12345
 for (; --temp - src > 0; temp, src++)
 {
  char c = *src;
  *src = *temp;
  *temp = c;
 }
 
}

void main()
{
 char ch[10] = "1234";
 char temp[10] = "ab";

 printf("strlen(%s): %d \n", ch, strlen(ch));
 
 //strcpy(temp, ch);
 printf("strcpy(%s, temp) = > temp : %s \n", ch, temp);

 printf("strcmp(%s, %s) : %d \n", ch, temp, strcmp(ch, temp));

 printf("atoi(%s): %d \n", ch, atoi(ch));

 itoa(12340, ch);
 printf("itoa(12340, ch): %s \n", ch);
}

'Computer Language > c 언어' 카테고리의 다른 글

strcmp 활용  (0) 2014.04.10
NULL == '0' == 0  (0) 2014.04.10
구조체 배열  (0) 2014.04.09
열거자 에러를 선언시  (0) 2014.04.09
열거자  (0) 2014.04.09

#include<stdio.h>
#include<stdlib.h>
#include<string.h>

typedef struct phone
{
 char name[20];
 char number[20];
}Phone;

void add_phone(Phone* p, char* name, char* number)
{
 for (int i = 0; i < 10; i++)
 {
  if (strcmp(p[i].name, "") == 0 && strcmp(p[i].number, "") == 0){ //p[i].number이랑 "" 일시 0임.
   strcpy_s(p[i].name, name); //p[i].name에 name을 복사.
   strcpy_s(p[i].number, number);
   printf("%s %s \n", p[i].name, p[i].number);
   return;
  }
  
 }
 printf("넘쳐요\n");
}

void fine_phone(Phone* p, char* name)
{
 for (int i = 0; i < 10; i++)
 {
  if (strcmp(p[i].name, name) == 0){ //p[i].name이랑 name 일시 0임.
   printf("%s %s \n", p[i].name, p[i].number);
   return;
  }

 }
}
void del_phone(Phone* p, char* name, char* number)
{
 for (int i = 0; i < 10; i++)
 {
  if (strcmp(p[i].name, name) == 0 && strcmp(p[i].number, number) == 0){
   strcpy_s(p[i].name, "a");
   strcpy_s(p[i].number, "b");
   printf("name= %s number= %s \n", p[i].name, p[i].number);
   return;
  }
 }
}
void show_phone(Phone* p)
{
 for (int i = 0; i < 10; i++)
 {
  printf("name %s \t number %s\n", p[i].name, p[i].number);
 }
}

void main(){
 Phone phone[10] = {}; //10 full -> 더이상 저장할 수 없습니다

 for (int i = 0; i < 10; i++)
 {
  phone[i] = { "", "" };
 }

 add_phone(phone, "gameja1", "010-3344-5959");
 add_phone(phone, "gameja2", "010-3224-5959");
 add_phone(phone, "gameja3", "010-3344-5959");
 add_phone(phone, "gameja4", "010-3224-59533349");
 add_phone(phone, "gameja5", "010-3344-5923259");
 add_phone(phone, "gameja6", "010-3344-5959");
 add_phone(phone, "gameja7", "010-3224-5959");
 add_phone(phone, "gameja8", "010-3344-593239");
 add_phone(phone, "gameja9", "010-3344-5923259");
 add_phone(phone, "gameja10", "010-3344-5959");
 add_phone(phone, "gameja11", "010-3224-5959");
 add_phone(phone, "gameja12", "010-3344-593239");
 add_phone(phone, "gameja13", "010-3224-5959");
 add_phone(phone, "gameja14", "010-3344-593239");

 show_phone(phone);

 fine_phone(phone, "gameja4");

 del_phone(phone, "gameja1", "010-3344-5959");
}

 

 /*
 while (1){
  printf("1:입력\n");
  printf("2:출력\n");
  printf("3:종료\n");
  scanf_s("%d", &input, 1);

  switch (input)
  {
  case 1:
  {
      printf("이름/전화번호입력 : ");

  }
   break;

  case 2:
  {
      printf("이름\t\t전화번호\n");
      for (int i = 0; i < 10; i++)
      {
      // printf("%s\t\t%d\n",phone[count].name, phone[count].number, 1);
      }
  }
   break;

  case 3:
  {
      exit(0);
      break;
  }
  default:
   break;
  }
 }
}
*/

 

 

'Computer Language > c 언어' 카테고리의 다른 글

NULL == '0' == 0  (0) 2014.04.10
라이브러리  (0) 2014.04.09
열거자 에러를 선언시  (0) 2014.04.09
열거자  (0) 2014.04.09
구조체 p->age; (*p).age; 똑같다.  (0) 2014.04.09

// 열거타입 enum

#include<stdio.h>

typedef enum week
{
 ERROR_DONT_MOVE = 1,
 ERROR_DONT_HAVE_MONEY = 2,
 ERROR_SOCKET = 10
}ERROR;

void main()
{
 if (1)
 {
  printf("ERROR: %d, \n", ERROR_DONT_MOVE);
  printf("ERROR: %d, \n", ERROR_SOCKET);
 }
}

 

 

'Computer Language > c 언어' 카테고리의 다른 글

라이브러리  (0) 2014.04.09
구조체 배열  (0) 2014.04.09
열거자  (0) 2014.04.09
구조체 p->age; (*p).age; 똑같다.  (0) 2014.04.09
구조체  (0) 2014.04.09

// 열거타입 enum

#include<stdio.h>

enum week
{
 ONE = 2,  // 열거자 2로 초기화시 2, 3, 4 값이 들어가게 됨.
 TWO, THREE // .....
};

void main()
{
 enum week w;
 w = TWO;

 printf("%d, THREE:%d \n", w, THREE);
}

 

'Computer Language > c 언어' 카테고리의 다른 글

라이브러리  (0) 2014.04.09
구조체 배열  (0) 2014.04.09
열거자 에러를 선언시  (0) 2014.04.09
구조체 p->age; (*p).age; 똑같다.  (0) 2014.04.09
구조체  (0) 2014.04.09

+ Recent posts