calloc은 할당된 공간의 값을 모두 0으로 바꾸므로 초기화가 필요한 경우 calloc

 

ex) (int*)calloc(size,sizeof(int));

'전공부셔 > c' 카테고리의 다른 글

정수 문자열 변환  (0) 2023.03.05
[프로그래머스] 특정 문자 제거하기  (0) 2023.03.05
[프로그래머스] 문자 반복 출력하기  (1) 2023.02.27
정렬  (0) 2023.02.26
[프로그래머스] 숨어있는 숫자의 덧셈 (1)  (0) 2023.02.26
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
char* solution(const char* my_string, int n) {
    char* answer = (char*)malloc(sizeof(char)*strlen(my_string)*n+1);
    int index = 0;
    for(int i=0; i<strlen(my_string); i++){
        for(int j=0; j<n; j++){
            answer[index++]=my_string[i];
        }
    }
    answer[strlen(my_string)*n]='\0';
    return answer;
}

마지막에 '\0' 값 넣어쥬기...***

'전공부셔 > c' 카테고리의 다른 글

[프로그래머스] 특정 문자 제거하기  (0) 2023.03.05
calloc과 malloc 차이  (0) 2023.03.05
정렬  (0) 2023.02.26
[프로그래머스] 숨어있는 숫자의 덧셈 (1)  (0) 2023.02.26
배열 원소 개수  (0) 2023.02.26

qsort(array,array_len,sizeof(int),compare);

 

*오름차순

int compare(const void *a , const void *b){
    if(*(int*)a > *(int*)b) return 1;
    else if(*(int*)a < *(int*)b) return -1;
    else return 0;
}

 

*내림차순

int compare(const void *a , const void *b){
    if(*(int*)a < *(int*)b) return 1;
    else if(*(int*)a > *(int*)b) return -1;
    else return 0;
}
#include <stdio.h>
#include <stdlib.h>

int solution(const char* my_string) {
    int answer = 0;
    for(int i=0; i<strlen(my_string); i++){
        if(isdigit(my_string[i])) answer += my_string[i]-'0';
    }
    return answer;
}

'전공부셔 > c' 카테고리의 다른 글

[프로그래머스] 문자 반복 출력하기  (1) 2023.02.27
정렬  (0) 2023.02.26
배열 원소 개수  (0) 2023.02.26
[프로그래머스] 문자열 뒤집기  (0) 2023.02.26
size_t, unsigned int 차이  (0) 2023.02.26

sizeof(배열명)/sizeof(자료형)

'전공부셔 > c' 카테고리의 다른 글

정렬  (0) 2023.02.26
[프로그래머스] 숨어있는 숫자의 덧셈 (1)  (0) 2023.02.26
[프로그래머스] 문자열 뒤집기  (0) 2023.02.26
size_t, unsigned int 차이  (0) 2023.02.26
bool  (0) 2023.02.26
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
char* solution(const char* my_string) {
    char* answer = (char*)malloc(strlen(my_string));
    for(int i=0; i<=strlen(my_string); i++){
        answer[i]=my_string[strlen(my_string)-1-i];
    }
    return answer;
}

'전공부셔 > c' 카테고리의 다른 글

정렬  (0) 2023.02.26
[프로그래머스] 숨어있는 숫자의 덧셈 (1)  (0) 2023.02.26
배열 원소 개수  (0) 2023.02.26
size_t, unsigned int 차이  (0) 2023.02.26
bool  (0) 2023.02.26

=> 운영체제에 따라 사이즈가 변하는 지 여부

 

*문자열이나 메모리의 사이즈를 나타낼 때 사용

 

<size_t>

-> 이론상 가장 큰 사이즈를 담을 수 있는 부호없는(unsigned) 데이터 타입.

printf()로 출력하려면 %ld or %zu

 

32비트 운영체제에서는 '부호없는 32비트 정수',

64비트 운영체제에서는 '부호없는 64비트 정수'

=> 고정된 사이즈 

 

<unsigned int>

64비트 운영체제라고 해서 꼭 64비트 x, 32비트 일수도 있음

=> 가변

'전공부셔 > c' 카테고리의 다른 글

정렬  (0) 2023.02.26
[프로그래머스] 숨어있는 숫자의 덧셈 (1)  (0) 2023.02.26
배열 원소 개수  (0) 2023.02.26
[프로그래머스] 문자열 뒤집기  (0) 2023.02.26
bool  (0) 2023.02.26
#include <stdio.h>
#include <stdbool.h>

int main() {

  bool b1 = true;

  if(b1==true){
    printf("참\n");
  }
  bool b2 = false;
  if(b2==false){
    printf("거짓\n");
  }
  
  return 0;
}

 

bool -> true, false

'전공부셔 > c' 카테고리의 다른 글

정렬  (0) 2023.02.26
[프로그래머스] 숨어있는 숫자의 덧셈 (1)  (0) 2023.02.26
배열 원소 개수  (0) 2023.02.26
[프로그래머스] 문자열 뒤집기  (0) 2023.02.26
size_t, unsigned int 차이  (0) 2023.02.26

+ Recent posts