분류 | 게시판 |
베스트 |
|
유머 |
|
이야기 |
|
이슈 |
|
생활 |
|
취미 |
|
학술 |
|
방송연예 |
|
방송프로그램 |
|
디지털 |
|
스포츠 |
|
야구팀 |
|
게임1 |
|
게임2 |
|
기타 |
|
운영 |
|
임시게시판 |
|
프로젝트 하는데 막히는 부분이 있어서 혹시나 질문 올려봅니다. ㅠ
#include<iostream>
#include<fstream>
#include<string>
using namespace std;
#define max 100
char inputline[max];
class result{
private:
char term[10];
public:
void result_show(char*);
result();
result(char*);
};
void result::result_show(char *term)
{
if(term="0"){
ifstream inFile("result.txt");
while(!inFile.eof()){
inFile.getline(inputline, max);
cout<<inputline<<endl;
}
inFile.close();
}
else{
ifstream inFile("result.txt");
while(!inFile.eof()){
inFile.getline(inputline, max);
if(!strncmp(inputline, term, 12)){
cout<<inputline<<endl;
}
inFile.close();
}
}
}
result::result(){
strcpy(term, "0");
result_show(term);
}
result::result(char* in){
strcpy(term,in);
cout<<term;
result_show(term);
}
int main(){
int sel=0;
char s_term[10];
cout<<"1. 전체성적보기"<<endl;
cout<<"2. 학기별성적보기"<<endl;
cin>>sel;
switch(sel){
case 1:
result();
break;
case 2:
cout<<"원하는 학기를 입력하세요. ex)201202"<<endl;
cin>>s_term;
result(s_term);
break;
}
return 0;
}
텍스트 파일의 내용
201201 웹 프로그래밍 23 3학점 A+
201201 객체지향 32 2학점 B
201201 음악의 이해 22 3학점 B+
--------------------------------------------
201201 8학점 3.75
201202 산과 인생 12 2학점 A
201202 알고리즘 11 3학점 B
201202 자바 44 3학점 C+
--------------------------------------------
201202 8학점 3.00
전체출력과 원하는 학기만 출력 할수 있게 하려는데
전체학기는 출력이 되는데 이것도 제대로 한건지 모르겠고
원하는 학기만 출력이 안되네요
strncmp를 이용해 각 라인앞부분을 비교해서 동일할 경우만 출력하려는데...
어디가 문제일까요?ㅠ?
죄송합니다. 댓글 작성은 회원만 가능합니다.