본문 바로가기

C 프로그래밍

(29)
구조체 배워보기.. #include #include #include struct food { char name[15]; int portion_weight; int calories; } meal1, meal2, meal3; int result(){ return meal1.calories + meal2.calories + meal3.calories; } // 얘는 작동안함. void init(struct food setMeal, char *setName, int setWeight, int setCalories){ strcpy(setMeal.name, setName); setMeal.portion_weight = setWeight; setMeal.calories = setCalories; } void main(){ strcpy(..
MakeUp Quiz(풀이) #include #include #define True 1 #define False 0 void swapStr(char *base, char *target); void shift(char *pstr, int n); void order_char(char *pstr, int n); double sum_primed_position(double arr[], int n); void bubble(double arr[], int n); void swap(double*, double*); int occurrence(char *pstr, char c); void zigzag_scan(double *pa, double *pza); int isPrimed(int number); void swapStr(char *base, ..
MakeUp Quiz 다음 코드를 활용하여 프로그램을 완성하라. void shift(char *pstr, int n); void order_char(char *pstr, int n); double sum_primed_position(double arr[], int n); void bubble(double arr[], int n); void swap(double*, double*); int occurrence(char *pstr, char c); void zigzag_scan(double *pa, double *pza); main(int argc, char *argv[]) { int num; char c_array[128]; double *a; double coeff[4][4], zz_coeff[16]; if(argc
atoi 함수를 이용해서 문자열의 숫자들의 합을 구하기 #include #include int checkNum(char *str); int getSize(char *str); int numCharToInt(char *str); int checkNum(char *str){ int sum = 0; int i; // 합을반영할숫자, 인덱스옮겨갈변수 char letter; for(i = 0 ; i '/' && str[i] < ':'){ letter = str[i]; sum += letter - '0'; } } return sum; } int getSize(char *str){ int size = 0; int i; for(i = 0;;i++){ if(str[..
문자열 버블정렬~ #include #include #include #define SIZE 1024 void bubbleSort(char *str); void swap(char *base, char *target); int getSize(char *str); void bubbleSort(char *str){ int i, j; for(i = 0 ; i < getSize(str) ; i++) { for (j = 0 ; j < getSize(str) ; j++) { if (str[i] < str[j]) swap(&str[i],&str[j]); } } } int getSize(char *str){ int size = 0; int i; for(i = 0;;i++){ if(str[i] == '\0') break; else size++..
단어의 갯수 골라내기 확장팩 #include #include #include #define SIZE 1024 int word_cnt(); int word_cnt(char *string){ int count = 0; int nonAlphaContinued = 0; while(*string != '\0'){ // 문장이끝날대 while (isspace(*string)) // 포인터가가르키는인덱스가공백인경우 string++; //다음인덱스로포인터를변경 if(*string != '\0'){ count++; while (!isspace(*string) && *string != '\0') { // 빈칸이아니고, 문장이끝이나지도않을때 if (isalpha(*string)) {// 알파벳인경우 string++; } else if(isalpha(*..
단어의 갯수를 세는 소스 #include #include #include #define SIZE 1024 int word_cnt(); int word_cnt(char *string){ int count = 0; while(*string != '\0'){ // 문장이 끝날대 while (isspace(*string)) // 포인터가 가르키는 인덱스가 공백인 경우 string++; //다음 인덱스로 포인터를 변경 if(*string != '\0'){ count++; while (!isspace(*string) && *string != '\0') string++; } } return count; } int main(){ char string[SIZE]; printf("입력하신 단어의 수를 세는 프로그램이다?"); gets(string..
calloc 함수를 통한 동적 2차원 배열 만들기 #include #include int main(){ int iNum, i, j, temp; int **value; int first = 0; int last = 300; printf("몇 명인가요?\n"); scanf("%d", &iNum); value = (int **)calloc(iNum, sizeof(int *)); for(i = 0 ; i < iNum ; i++) { value[i] = (int *)calloc(4, sizeof(int)); printf("성적을 입력해주세요\n"); for (j = 0 ; j < 3 ; j++) { printf("점수?\n"); scanf("%d", &temp); value[i][j] = temp; value[i][3] += temp; } } for(i = 0 ..