/***************************************************************************
*
* Date : 2005-04-09
* Copyright : aucd29
* E-mail : aucd29@daum.net
*
* 기존프로그램의 main을 수정해서 모든 행의 길이와 문자들을 출력하도록
* 하는 프로그램
*
***************************************************************************/
#include <stdio.h>
#define MAXLINE 1000
#define AR_MAX 100
int getline(char line[],int maxline);
void copy(char to[AR_MAX][MAXLINE],char from[],int *nCnt);
void ResultOut(char to[AR_MAX][MAXLINE], int nStrLen[], int *nCnt);
int main()
{
int len;
// int max;
char line[MAXLINE];
char longest[AR_MAX][MAXLINE];
int nStrLen[AR_MAX];
int nCnt=0,i=0;
for(i=0;i<AR_MAX;++i) nStrLen[i] = 0; // 변수 초기화
while((len = getline(line,MAXLINE)) > 0)
{
if(AR_MAX<nCnt) break;
copy(longest, line, &nCnt); // 문단 배열에 복사
nStrLen[nCnt] = len; // 단어 카운트
++nCnt;
}
if(nCnt >0)
{
ResultOut(longest, nStrLen, *nCnt);
}
return 0;
}
int getline(char s[], int lim)
{
int c, i;
for(i=0;i<lim-1 && (c=getchar()) != EOF && c!='\n'; ++i)
s[i] = c;
if(c == '\n')
{
s[i] = c;
++i;
}
s[i] = '\0';
return i;
}
void copy(char to[AR_MAX][MAXLINE], char from[], int *nCnt)
{
int i=0;
// 글자를 복사한다.... 배열이므로 하나씩...
while((to[*nCnt][i] = from[i]) != '\0')
++i;
}
void ResultOut(char to[AR_MAX][MAXLINE], int nStrLen[], int *nCnt)
{
int i,j=0, nMultiCmtStart=0;
for(i=0;i<AR_MAX;++i)
{
// 코멘트를 지우자.
while(to[i][j]!='\0')
{
// 한줄 주석 지우기
if(to[i][j]=='/' && to[i][j+1]=='/')
{
//printf("%d, %d", i, j);
//
// 첫 줄 일경우는 배열을 다시 정의 하자.
//
if(j==0)
{
UpLine(char to[AR_MAX][MAXLINE],i, *nCnt);
}
else
{
to[i][j] = '\n';
to[i][j+1] = '\0';
}
}
// 여러줄 주석 지우기
if(to[i][j]=='/' && to[i][j+1]=='*')
{
nMultiCmtStart = 1;
to[i][j] = '\n';
to[i][j+1] = '\0';
}
if(to[i][j]=='*' && to[i][j+1]=='/')
{
nMultiCmtStart = 0;
// if(
to[i][j] = '\n';
to[i][j+1] = '\0';
}
++j;
}
if(nMultiCmtStart)
{
to[i][0] = '\n';
to[i][1] = '\0';
}
j=0; // 첫번째 줄로 이동하자.
}
for(i=0;i<AR_MAX;++i)
{
if(nStrLen[i] > 0)
printf("%s", to[i]);
}
}
void UpLine(char to[AR_MAX][MAXLINE], int n)
{
int i=0;
while(to[n][i]!='\0')
{
}
}
*
* Date : 2005-04-09
* Copyright : aucd29
* E-mail : aucd29@daum.net
*
* 기존프로그램의 main을 수정해서 모든 행의 길이와 문자들을 출력하도록
* 하는 프로그램
*
***************************************************************************/
#include <stdio.h>
#define MAXLINE 1000
#define AR_MAX 100
int getline(char line[],int maxline);
void copy(char to[AR_MAX][MAXLINE],char from[],int *nCnt);
void ResultOut(char to[AR_MAX][MAXLINE], int nStrLen[], int *nCnt);
int main()
{
int len;
// int max;
char line[MAXLINE];
char longest[AR_MAX][MAXLINE];
int nStrLen[AR_MAX];
int nCnt=0,i=0;
for(i=0;i<AR_MAX;++i) nStrLen[i] = 0; // 변수 초기화
while((len = getline(line,MAXLINE)) > 0)
{
if(AR_MAX<nCnt) break;
copy(longest, line, &nCnt); // 문단 배열에 복사
nStrLen[nCnt] = len; // 단어 카운트
++nCnt;
}
if(nCnt >0)
{
ResultOut(longest, nStrLen, *nCnt);
}
return 0;
}
int getline(char s[], int lim)
{
int c, i;
for(i=0;i<lim-1 && (c=getchar()) != EOF && c!='\n'; ++i)
s[i] = c;
if(c == '\n')
{
s[i] = c;
++i;
}
s[i] = '\0';
return i;
}
void copy(char to[AR_MAX][MAXLINE], char from[], int *nCnt)
{
int i=0;
// 글자를 복사한다.... 배열이므로 하나씩...
while((to[*nCnt][i] = from[i]) != '\0')
++i;
}
void ResultOut(char to[AR_MAX][MAXLINE], int nStrLen[], int *nCnt)
{
int i,j=0, nMultiCmtStart=0;
for(i=0;i<AR_MAX;++i)
{
// 코멘트를 지우자.
while(to[i][j]!='\0')
{
// 한줄 주석 지우기
if(to[i][j]=='/' && to[i][j+1]=='/')
{
//printf("%d, %d", i, j);
//
// 첫 줄 일경우는 배열을 다시 정의 하자.
//
if(j==0)
{
UpLine(char to[AR_MAX][MAXLINE],i, *nCnt);
}
else
{
to[i][j] = '\n';
to[i][j+1] = '\0';
}
}
// 여러줄 주석 지우기
if(to[i][j]=='/' && to[i][j+1]=='*')
{
nMultiCmtStart = 1;
to[i][j] = '\n';
to[i][j+1] = '\0';
}
if(to[i][j]=='*' && to[i][j+1]=='/')
{
nMultiCmtStart = 0;
// if(
to[i][j] = '\n';
to[i][j+1] = '\0';
}
++j;
}
if(nMultiCmtStart)
{
to[i][0] = '\n';
to[i][1] = '\0';
}
j=0; // 첫번째 줄로 이동하자.
}
for(i=0;i<AR_MAX;++i)
{
if(nStrLen[i] > 0)
printf("%s", to[i]);
}
}
void UpLine(char to[AR_MAX][MAXLINE], int n)
{
int i=0;
while(to[n][i]!='\0')
{
}
}
'Native > C' 카테고리의 다른 글
10진수를 2진수로 메모리상에서비교 & 이용 (0) | 2013.10.02 |
---|---|
16진수를 10진수로 바꾸자 (0) | 2013.10.02 |
예제 1-22 (0) | 2013.10.02 |
예제 1-21 (0) | 2013.10.02 |
예제 1-19 (0) | 2013.10.02 |