Skip to content

Instantly share code, notes, and snippets.

@chorim
Created May 28, 2019 17:33
Show Gist options
  • Save chorim/ef62966382e2be30d24601b04aa68833 to your computer and use it in GitHub Desktop.
Save chorim/ef62966382e2be30d24601b04aa68833 to your computer and use it in GitHub Desktop.
요청)과제-2-2
//
// main.c
// test
//
// Created by 유키유키 on 2019. 5. 29..
// Copyright © 2019년 유키유키. All rights reserved.
//
//
// Sorry my dirty code :(
// I'm noob...
//
#include <stdio.h>
#define MAX 100
int main (void)
{
char temp;
char str[MAX][MAX] = {};
printf("문장을 입력하세요:");
int row = 1;
scanf("%[^\n]", str[0]);
int i = 0, col = 0;
while (str[0][i] != '\0') {
if (str[0][i] == (char)32) { // compare char ''
row++;
i++;
col = 0;
continue;
}
str[row][col] = str[0][i];
col++;
i++;
}
scanf("%c", &temp); // clear buffer
printf("이를 거꾸로 하면:");
for (int j = row; j > 0; j--) {
printf("%s", str[j]);
if (j > 1) printf(" "); // space
}
for(;;){}
return 0;
}
한 줄을 읽어들여 단어로 분리하여 문자열의 배열(2차원 문자배열)에 저장하고, 읽어들인 문장을 단어단위로 역순으로 출력하는 프로그램을 작성하시오.
실행 예는 다음과 같다.
언어 : C언어
===============================
문장을 입력하세요: It's a beautiful day, isn't it?
이를 거꾸로 하면: it? isn't day, beautiful a It's
===============================
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment