문자열에 관한 함수를 만드는데 코드 한번 봐주시면 감사하겠습니다.
함수 네가지를 만들어야 하는데 생각대로 잘 안되네요 ㅜㅜ
1.
int CountTabs(const char* string)
{
int tabs = 0;
while(string != EOF)
{
if(string == '\t')
{
tabs ++;
}
}
return tabs;
}
1번. 스트링에 탭이 얼마나 있나 카운트하고 카운트를 반환하는 함수. 이렇게 적으면 문제 없을까요??
2.
int SubstituteChar(char* string, char oldChar, char newChar)
{
int count;
int s;
for (int s = 0; s < newChar[s]; s++)
if (oldChar[s] != newChar[s])
{
count++;
}
return count;
};
2번. oldChar과 newChar을 치환하고 치환의 횟수를 반환하는 함수. 이거 전혀 모르겠어요 ㅜㅜ 제가 쓴 코드는 순 엉터리...
3.
void CalculateLengths(const char* string, int tabSize, int *stringLength, int *displayLength)
{
int count = 0;
for (int i = 0; *(count + i) != 0; i++;)
{
count++;
}
*stringLength = count;
*displayLength = *stringLength + (CountTabs(*string)-1)*tabSize;
};
문자열 길이랑 프린트 문자열 길이를 구하여라.
print length is the number of characters that will be
required to display the string after the tabs are
expanded into spaces.
프린트 문자열 길이 - 문자열의 탭이 스페이스로 취급되어 디스플레이 되는데 필요한 길이... 대충 이런뜻?
4.
int CountWords(const char* string)
{
int i = 0;
int count = 0;
while (&string[i] != "\0")
{
if (&string[i] == "\t")
{
count++;
}
i++;
}
return count;
};
문자열에서 단어 수가 몆개인지 카운트하는 함수를 만들어야 하는데 이렇게 짜는게 맞는지 모르겠네요.
코드 한번 봐주시고 문제점 있으면 지적 부탁드려요.
감사합니다.
"아무리 해봐도 안되네요. 어떻게 하는지 모르겠어요"
"아무리 해봐도 안되네요. 어떻게 하는지 모르겠어요" 밖에 없는 질문은 답하기가 매우 곤란합니다.
질문자가 어느 정도 수준인지, 어디까지 시도해봤는지, 어디서 막혔는지, 어디서부터 설명드려야 하는지 하나도 모르는데, 무슨 답을 드리겠습니까.
답변을 바란다면 질문에도 성의를 보이셔야지요.
댓글 달기