我有一個文本文件,它看起來像這樣:複製列
Flooding refers to all water that overflows a node, whether it ponds or not.
--------------------------------------------------------------------------
Total Maximum
Maximum Time of Max Flood Ponded
Hours Rate Occurrence Volume Depth
Node Flooded CMS days hr:min 10^6 ltr Meters
--------------------------------------------------------------------------
1064 0.15 0.000 0 00 00 0.000 0.35
1065 0.25 0.078 0 00 09 0.049 0.41
1130 0.25 0.626 0 00 00 0.106 0.90
1155 0.24 0.098 0 00 07 0.073 0.61
1173 0.25 0.106 0 00 15 0.022 0.76
我想要複製的數值列(無文本),使得生成的文件就像這樣:
1064 0.15 0.000 0 00 00 0.000 0.35
1065 0.25 0.078 0 00 09 0.049 0.41
1130 0.25 0.626 0 00 00 0.106 0.90
1155 0.24 0.098 0 00 07 0.073 0.61
1173 0.25 0.106 0 00 15 0.022 0.76
到現在我已設法在C做此代碼:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
void main()
{
FILE *fs,*ft;
int ch;
int c;
fs=fopen("node.txt","r");
if (fs=NULL)
{
puts("cannot open source file");
exit(0);
}
ft=fopen("new_node.txt","w");
do
{
ch=fgetc(fs);
if (ch=EOF)
break;
else
{
if (ch>0)
fputc(ch,ft);
}
ch++;
}
while(1);
fclose(fs);
fclose(ft);
return 0;
}
的問題是,什麼是走出來的吧。任何人都可以在這方面提供幫助並提供工作代碼。
我會用C以外的其他工具來執行這個任務,比如awk(或者perl,或者python) –
實際上我不知道perl或者python。這就是爲什麼我試圖C.它可能是DOS程序嗎? – krishcal23
以下兩種語言都增加了一些解決方案。如果你不認識他們,就去學習吧!這是值得的時間。此外,恕我直言python很容易拿起 –