1) 5ÁÙ ÀÌÇÏÀÇ ¿©·¯ÁÙ¿¡ ¿øÇÏ´Â ¹®ÀåÀ» ÀÔ·ÂÇϰí ÀÔ·ÂÀÌ ´Ù µÇ¾úÀ¸¸é »õ·Î¿î Á٠óÀ½¿¡ enter ۸¸À» ÀÔ·ÂÇÏ¸é °á°ú°ª Ãâ·Â
2) ÅäÅ«Àº ºóÄ, ½°Ç¥, ¸¶Ä§Ç¥, ´À³¦Ç¥, ÅÇ, ±×¸®°í ¼ýÀÚ ÀÔ´Ï´Ù.
3) ´Ü¾îÀÇ Ã¹ ±ÛÀÚ°¡ ¾ËÆÄºªÀÇ ´ë¹®ÀÚÀÏ °æ¿ì µ¿ÀÏÇÑ ¼Ò¹®ÀÚº¸´Ù ¿ì¼±¼øÀ§°¡ ³ô°Ô Á¤·ÄÇÏ¿© Ãâ·Â
4) µ¿ÀÏÇÑ ¾ËÆÄºªÀ¸·Î ½ÃÀÛÇÏ´Â ´Ü¾î°¡ ¿©·¯°³ ÀÖÀ»¶§¿¡´Â ¾ÕÂÊ¿¡ ³ª¿Â ´Ü¾î¸¦ ¸ÕÀú Ãâ·ÂÇÑ´Ù.
´ÙÀ½ °úÁ¤À» ¼öÇàÇϴµ¥ Á¤»óÀûÀ¸·Î ÀÛµ¿À» Çϴµ¥
¿À·ù ; Run-Time Check Failure #2 - Stack around the variable 'Æ÷ÀÎÅÍ' was corrupted
¶ó°í ¿À·ù°¡ ¶å´Ï´Ù.
¾îµð¿¡¼ ¹®Á¦°¡ ÀÖ³ª¿ä?
#include <stdio.h>
#include <string.h>
int input(char str[][100]);
void processing_tok(char * str_cpy[], char str[][100], int count);
int processing_cpy(char * str_cpy[], char str_temp_cpy[][100]);
void output(char str_temp_cpy[][100], char *str_cpy[], int max);
int main()
{
int i = 0;
int line = 0;
int count = 0;
char str[5][100] = { "" };
char * str_cpy[200];
char str_temp_cpy[5][100] = { NULL };
count = input(str);
processing_tok(str_cpy, str, count);
line = processing_cpy(str_cpy, str_temp_cpy);
output(str_temp_cpy, str_cpy, line);
}
int input(char str[][100])
{
int i = 0;
printf("ÀÔ·Â: ");
while (true)
{
gets(str[i]);
if (str[i][0] == '\0')
break;
++i;
}
return i;
}
void processing_tok(char * str_cpy[], char str[][100], int count)
{
int i = 0;
int j = 0;
char tok[] = " ,.!\t0123456789";
for (i = 0; i < count; ++i)
{
str_cpy[j] = strtok(str[i], tok);
while (true)
{
if (str_cpy[j] == NULL)
break;
++j;
str_cpy[j] = strtok(NULL, tok);
}
}
}
int processing_cpy(char * str_cpy[], char str_temp_cpy[][100])
{
int i = 0;
int max = 0;
while (str_cpy[i] != NULL)
{
strcpy(str_temp_cpy[i], str_cpy[i]);
++i;
}
max = i;
return max;
}
void output(char str_temp_cpy[][100], char *str_cpy[], int max)
{
int i = 0;
int j = 0;
int min = 0;
char temp[200] = { NULL };
for (i = 0; i< max - 1; ++i)
{
min = i;
for (j = i + 1; j < max; ++j)
{
if (strcmp(str_temp_cpy[min], str_temp_cpy[j]) > 0)
min = j;
}
strcpy(temp, str_temp_cpy[i]);
strcpy(str_temp_cpy[i], str_temp_cpy[min]);
strcpy(str_temp_cpy[min], temp);
}
printf("Ãâ·Â: ");
for (i = 0; i < max; ++i)
{
printf(" %s", str_temp_cpy[i]);
}
printf("\n");
}