문자열에 관한 함수를 만드는데 코드 한번 봐주시면 감사하겠습니다.

zszsd의 이미지

함수 네가지를 만들어야 하는데 생각대로 잘 안되네요 ㅜㅜ

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;

};

문자열에서 단어 수가 몆개인지 카운트하는 함수를 만들어야 하는데 이렇게 짜는게 맞는지 모르겠네요.

코드 한번 봐주시고 문제점 있으면 지적 부탁드려요.

감사합니다.

 의 이미지

"아무리 해봐도 안되네요. 어떻게 하는지 모르겠어요" 밖에 없는 질문은 답하기가 매우 곤란합니다.
질문자가 어느 정도 수준인지, 어디까지 시도해봤는지, 어디서 막혔는지, 어디서부터 설명드려야 하는지 하나도 모르는데, 무슨 답을 드리겠습니까.
답변을 바란다면 질문에도 성의를 보이셔야지요.

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.