An easy problem?

NoneNoneNone 2003-09-14 05:45:07
I have a txt dataset, it looks as follow:
1001 01/01/2000 xx xx
1001 02/01/2000 xx xx
1002 01/03/2000 xx xx
1002 02/04/2000 xx xx
1002 03/16/2000 xx xx
1003 01/11/2000 xx xx
1004 01/15/2000 xx xx
1004 03/10/2000 xx xx

The first column is a subject ID second column is visist date, the third and fourth column can be characters or numbers.

I want to add a new column according to the first column(ID) and second column (date) to record visit time of a subject. The results should look like follow:

1001 01/01/2000 xx xx 1
1001 02/01/2000 xx xx 2
1002 01/03/2000 xx xx 1
1002 02/04/2000 xx xx 2
1002 03/16/2000 xx xx 3
1003 01/11/2000 xx xx 1
1004 01/15/2000 xx xx 1
1004 03/10/2000 xx xx 2

...全文
113 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
shenyiwen 2003-09-20
  • 打赏
  • 举报
回复
use awk
frank026 2003-09-15
  • 打赏
  • 举报
回复
in my opinion,if each "1001 01/01/2000 xx xx" is of a fixed size,then you can use the function fseek() to position the place where you want to add the data such as 1 2 3 …….then each time some ID has visited you can change the right
data.
NoneNoneNone 2003-09-15
  • 打赏
  • 举报
回复
Hi,the last column "1 2 3 1 2 3 1 1 2 " should be automatically produced according to column 1 (ID) and column 2 (Date). Suppose I have 10,000 data, we cannot write a column by ourselves, right?
TianGuangZao 2003-09-15
  • 打赏
  • 举报
回复
write down last column (1 2 3 1 2 3 1 1 2 ...) to a file i.e. named num.txt.

open dataset.txt:
1001 01/01/2000 xx xx
...
u know at the end of each line, there is a newline sign '\n' that terminate the current line although u cant see it under txt mode.
So what we shall do is to check each char in dataset and find '\n',
before it add a space and number read from num.txt.
Go down until end of the dataset.txt
NoneNoneNone 2003-09-14
  • 打赏
  • 举报
回复
Thanks,would you like to give me some specfic ideas?
pzytony 2003-09-14
  • 打赏
  • 举报
回复

up
pengzhenwanli 2003-09-14
  • 打赏
  • 举报
回复
you must write a new file then read the old file,write the old column to new file.
add the new column.
finished it .you can delete old file.rename new file to old file.
or you set aside a empty column.

69,371

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧