前田稔(Maeda Minoru)の超初心者のプログラム入門
ファイル名 | 説明 |
---|---|
Main.cpp | メインプログラムのファイル |
TextClass.h | Text Class のヘッダファイル |
TextClass.cpp | Text Class のプログラムファイル |
/*★ Text Object Class Main Program 前田 稔 ★*/ #include <stdio.h> #include <conio.h> #include "TextClass.h" //Main Program int main() { TextClass *tclass= NULL; char file[256]; tclass= new TextClass(); printf("入力ファイル名をタイプして下さい\n"); scanf_s("%s",file,256); tclass->GetText(file); tclass->PutMsg(100); printf("----------------------------------------\n"); tclass->PutMsg((tclass->m_P+50),100); printf("----------------------------------------\n"); tclass->PutMsg(); _getch(); if (tclass) delete tclass; } |
/*★ Text Class Header File 前田 稔 ★*/ #define SIZE 32766 class TextClass { protected: public: char m_Buf[SIZE+2]; //入出力バッファ char *m_P; //入出力バッファポインタ unsigned int m_Len; //入力長 TextClass(); //Constructor unsigned int GetText(char *file); void PutMsg(char *p, unsigned int siz); void PutMsg() { PutMsg(m_P,m_Len); }; void PutMsg(unsigned int siz) { PutMsg(m_P,siz); }; }; |
/*★ Text Class Program File 前田 稔 ★*/ #include <conio.h> #include "TextClass.h" //Constructor TextClass::TextClass() { m_P= (char*)m_Buf; } //Get Text File unsigned int TextClass::GetText(char *file) { FILE *FI; //FILE の定義 if (fopen_s(&FI,file,"rb")!=0) { printf("INPUT FILE open error[%s]\n",file); return 0; } m_Len= fread(m_P,1,SIZE,FI); *(m_P+m_Len)= '\0'; fclose(FI); return m_Len; } //Text Buffer の表示 void TextClass::PutMsg(char *p, unsigned int siz) { char wk; wk= *(p+siz); *(p+siz)= '\0'; printf("%s\n",p); *(p+siz)= wk; } |
tclass->PutMsg(100); tclass->PutMsg((tclass->m_P+50),100); tclass->PutMsg(); |