c++ 프로그래밍 오류(class)

gjwjdals56의 이미지

#include "Copy.h"

using namespace std;

int main() {
Copy copy[100];

ifstream in("input.txt");
int school_num = 1;
int blank, length;
int s = 1, i=1;
char gradestr[100];
char numstr[100];
char classifystr[100];
char namestr[100];
char c_numstr[100];
char scorestr[100];
char* strptr1;
char* strptr2;
char* strptr3;
char* strptr4;
char* strptr5;
char* strptr6;
int len1, len2, len3, len4, len5, len6;
string _grade;
string _num;
string _classify;
string _name;
string _c_num;
string _score;

string line;

while (getline(in, line))
{
blank = line.find(",");
line.erase(blank, 1);
length = line.find(",");

while (length != -1)
{
if (s % 6 == 1)
{

_grade=line.substr(0, blank);
s++;
}

if (s % 6 == 2)
{
_classify = line.substr(blank, length - blank);
s++;
}
if (s % 6 == 3)
{
blank = length;
line.erase(blank, 1);
length = line.find(",");
_num = line.substr(blank, length - blank);
s++;

}
if (s % 6 == 4)
{
blank = length;
line.erase(blank, 1);
length = line.find(",");
_name = line.substr(blank, length - blank);
s++;

}
if (s % 6 == 5)
{
blank = length;
line.erase(blank, 1);
length = line.find(",");
_c_num = line.substr(blank, length - blank);
s++;

}
if (s % 6 == 0)
{
blank = length;
line.erase(blank, 1);
length = line.find(",");
_score = line.substr(blank, length - blank);

s++;
school_num++;

}
strcpy(gradestr , _grade.c_str());
strcpy(classifystr, _classify.c_str());
strcpy(numstr, _num.c_str());
strcpy(c_numstr, _c_num.c_str());
strcpy(scorestr, _score.c_str());
strcpy(namestr, _name.c_str());
len1 = strlen(gradestr) + 1;
len2 = strlen(classifystr) + 1;
len3 = strlen(numstr) + 1;
len4 = strlen(namestr) + 1;
len5 = strlen(c_numstr) + 1;
len6 = strlen(scorestr) + 1;
strptr1 = new char[len1];
strptr2 = new char[len2];
strptr3 = new char[len3];
strptr4 = new char[len4];
strptr5 = new char[len5];
strptr6 = new char[len6];
strncpy_s(strptr1, len1, gradestr,5);
strncpy_s(strptr2, len2,classifystr,8);
strncpy_s(strptr3, len3, numstr,8);
strncpy_s(strptr4, len4, namestr,26);
strncpy_s(strptr5, len5, c_numstr,3);
strncpy_s(strptr6, len6, scorestr,2);

copy[i].School_save(strptr1, strptr2, strptr3, strptr4, strptr5, strptr6);
copy[i].School_print();
i++;

blank = length;
line.erase(blank, 1);
length = line.find(",");
}
}

}
-----------------------------------------------------------------------------------------------------------
#include "Copy.h"

void Copy::School_save(char* grade_, char* classify_, char* num_, char* name_, char* c_num_, char* score_){
strncpy(grade, grade_,5);
strncpy(classify, classify_,8);
strncpy(num, num_,8);
strncpy(name, name_,26
strncpy(c_num, c_num_,3);
strncpy(score, score_,2);

}
void Copy::School_print(){
cout << grade << ","<< classify << "," << num << "," << name << "," << c_num<< "," < }
-----------------------------------------------------------------------------------------------------------
#pragma once
#define _CRT_SECURE_NO_WARNINGS
#include
#include
#include

using namespace std;

class Copy
{
char grade[5];
char num[8];
char classify[8];
char name[26];
char c_num[3];
char score[2];

public:
void School_save(char* grade_, char* classify_, char* num_, char* name_, char* c_num_, char* score_);
void School_print();
Copy() {

}
};

-----------------------------------------------------------------------------------------------------------
input파일을 읽어서 class를 이용해 두가지의 멤버함수를 만들어 (저장,출력)하기를 하고있습니다.
하다보니 출력을 하면 grade와 classify에서 출력이 이상하게 됩니다.
도와주세요ㅠㅠㅠ

File attachments: 
첨부파일 크기
Plain text icon input.txt1.73 KB
익명 사용자의 이미지

이 내용은 글 입력시에 자동으로 삭제 됩니다.

코드 입력 또는 들여쓰기가 필요한 내용의 경우,
<code> tag block 을 이용하여 작성 하십시오.

For code entry or indentation, use the <code> tag block.

<code lang="c">
if ( a != b ) {
    printf ("different a and b\n&qout;);
} else {
    printf ("same a and b\n");
}
</code>

댓글 달기

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 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.