English 中文(简体)
f 印刷错误数据
原标题:fprintf prints data in wrong order
  • 时间:2011-04-28 00:42:33
  •  标签:
  • c
  • printf

I have program in C language which prints some data to standard output. I used printf for this but I need to save data to file as well so I changed it to fprintf. Problem is, that with using fprintf, the data are in wrong order, doesn t matter, if the output is stdout or file.

  if(...) {
    out = fopen(param.F, "w");
  } else {
    out = stdout;
  }

  // some code here
  fprintf(out, "a");
  // more code
  fprintf(out, "b");
  ....

Atfer this, output is always different. 有时,

acb

有时,

ca

...... 我尝试了各种 set制和粉碎,但没有帮助。

EDIT:我也许必须知道,我在方案中使用某些<条码>fork(),但正如我前面提到的那样,在使用印本时没有任何问题。

我的产出如下:

1. 检查

2. 客户1:

3. 客户1:进入

5: 早餐

6:客户1:备妥

4:客户2:创造

7: 结 论

8: 酒吧:检查

9:客户2:进入

10: customer 1: served

11: barber: ready

12:客户2:准备好

13: barber: finished

14:酒吧:检查

15:客户2:服务

应按数字顺序排列。 该方案的结构如下:

int main() {
  pid = fork();
  if(pid == 0) {
    // barber printfs
  } else if (pid > 0) {
    // customer printfs
  } 
}
问题回答

(必须回答......)

如果没有,那么,如果你做print(印刷,......)或印刷(......)的话,那么纸面/纸面的缓冲就会不同。

几个过程是向同一档案撰写的,由于每个过程没有同步和不同的缓冲,产出都变得微不足道。

打印机和印本将具有不同的缓冲器。

如你说,根据产出,Im在提及该守则时,与你一样。

  1. Open file
  2. Fork
  3. Write the data

在此情况下,不同的种植作物是因为它是按随机顺序进行的,取决于每个儿童加工的时间。

最简单的解决办法只是用手稿填料,然后通过tee 进行双手操作,这样,你记录的所有 st子都能够存档。

如果你需要更复杂的解决办法,那么你就需要在进程之间建立一个国际太平洋共同体机制,并且要把所有文字都写在上级。

一种做法是,在你面前铺设一条管道(从socketpair,并从母工艺中的管道(利用选择(以避免阻挡))读到,然后登录在屏幕/档案中。 你们需要停下来,才能利用空洞避免失去。 我可能错过了几件事,因为我过去没有这样做。





相关问题
Fastest method for running a binary search on a file in C?

For example, let s say I want to find a particular word or number in a file. The contents are in sorted order (obviously). Since I want to run a binary search on the file, it seems like a real waste ...

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

Tips for debugging a made-for-linux application on windows?

I m trying to find the source of a bug I have found in an open-source application. I have managed to get a build up and running on my Windows machine, but I m having trouble finding the spot in the ...

Trying to split by two delimiters and it doesn t work - C

I wrote below code to readin line by line from stdin ex. city=Boston;city=New York;city=Chicago and then split each line by ; delimiter and print each record. Then in yet another loop I try to ...

Good, free, easy-to-use C graphics libraries? [closed]

I was wondering if there were any good free graphics libraries for C that are easy to use? It s for plotting 2d and 3d graphs and then saving to a file. It s on a Linux system and there s no gnuplot ...

Encoding, decoding an integer to a char array

Please note that this is not homework and i did search before starting this new thread. I got Store an int in a char array? I was looking for an answer but didn t get any satisfactory answer in the ...

热门标签