2008年6月9日 星期一

Visual C - 開檔案讀資料

try {
CStdioFile Sfile ((_T("BB_info.txt")),CFile::modeRead);
while (Sfile.ReadString (string)) {
TRACE (_T("%s\n"),string);
Inbuffer[i] = string;
i++; }
Sfile.Close ();
}

catch (CFileException* e) {
e->ReportError ();
e->Delete ();
return;
}
------------------------------------------------------

int Openfile() { // 讀取檔案資料,並將值存入S[陣列]
int i=0;
char filename[10];
cin >> filename;

ifstream fileptr;
fileptr.open(filename,ios::in);

while(!fileptr.eof()) {
i++;
fileptr >> s[i];
}
fileptr.close();
return i;
}
-----------------------------
/*fread IP format*/

int main ( int argc, char *argv[] )
{
FILE *fp;
struct packet
{
unsigned int tss;
unsigned int if_tsm;
unsigned int ver_IHL_ToS_TLen;
unsigned int Id_Flag_Frag_Off;
unsigned int TTL_Protocol_Checksum;
unsigned char SA0;
unsigned char SA1;
unsigned char SA2;
unsigned char SA3;
unsigned char DA0;
unsigned char DA1;
unsigned char DA2;
unsigned char DA3;
unsigned int SP_DP;
unsigned int Seq_Num;
unsigned int Ack_Num;
unsigned int DataOff;
} tsher;
int read_size;

fp=fopen(argv[1],"rb");

while (read_size=fread(&tsher,1,sizeof(tsher),fp) != 0){
printf("SA: %d.%d.%d.%d ",tsher.SA0,tsher.SA1,tsher.SA2,tsher.SA3);
printf("\tDA: %d.%d.%d.%d\n",tsher.DA0,tsher.DA1,tsher.DA2,tsher.DA3);
}

fclose(fp);
return 0;

}

沒有留言:

[c#] process 使用方法

寫法1. Process proc = new Process(); / /PowerShell.exe path proc.StartInfo.FileName = @"c:\Windows\System32\ WindowsPowerShell\v1.0\ powe...