[[확인문제 1]]
#include <iostream>
#include <string.h>
using std::cin; using std::cout; using std::endl;
#define MEMO_CNT 5
#define MEMO_LENGTH 1024
int main()
{
char *p[MEMO_CNT];
char buf[MEMO_LENGTH];
char len[MEMO_LENGTH];
for(int i=0; i < MEMO_CNT; i++)
{
cout << i+1 << "번째 입력 : ";
fflush(stdin);
cin.getline(buf, MEMO_LENGTH);
p[i] = new char [strlen(buf)+1];
strcpy(p[i], buf);
strcpy(len, p[0]);
}
for(i=0; i < MEMO_CNT; i++)
{
if(strlen(p[i]) > strlen(len))
strcpy(len, p[i]);
}
cout << endl << " 가장 긴 문자열 : " << len;
cout << endl << endl;
for(i=0; i<MEMO_CNT; i++)
{
cout << i+1 << "번쨰 출력 : ";
cout << p[i] <<endl;
}
for(i=0; i<MEMO_CNT; i++)
{
delete [] p[i];
}
return 0;
}
[[확인문제 2]]
#include <iostream>
#include <string>
using std::cin; using std::cout; using std::endl;
#define MEMO_CNT 5
#define MEMO_LENGTH 1024
int main()
{
char *p[MEMO_CNT];
char buf[MEMO_LENGTH];
char conch[MEMO_LENGTH];
for(int i=0; i<MEMO_CNT; i++)
{
cout << i+1 << "번째 입력 : ";
fflush(stdin);
cin.getline(buf, MEMO_LENGTH);
p[i] = new char[strlen(buf)+1];
strcpy(p[i], buf);
}
cout << endl;
for(i=0; i<MEMO_CNT; i++)
{
cout << i+1 << "번째 출력 : ";
cout << p[i] << endl;
}
cout << endl;
cout << "연결 출력\n";
strcpy(conch, p[0]);
for(i=0; i < MEMO_CNT; i++)
{
//cout << p[i];
strcat(conch, p[i]);
}
cout << conch << endl;
for(i=0; i<MEMO_CNT; i++)
{
delete [] p[i];
}
cout << endl;
return 0;
}