C语言 如何为涉及从文本文件打开并阅读它们的代码绘制流程图

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25489837/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 11:17:43  来源:igfitidea点击:

How to draw flowchart for code involving opening from text file and reading them

cwindowsflowchart

提问by problematic

like this code

喜欢这个代码

  fp1=fopen("Fruit.txt","r");
  if(fp1==NULL)
  {
       printf("ERROR in opening file\n");
       return 1;
  }
  else
  {
    for(i=0;i<lines;i++)//reads Fruits.txt database
    {
    fgets(product,sizeof(product),fp1);
    id[i]=atoi(strtok(product,","));
    strcpy(name[i],strtok(NULL,","));
    price[i]=atof(strtok(NULL,","));
    stock[i]=atoi(strtok(NULL,"\n"));
    }
  }
  fclose(fp1);

These symbols sound too similar to differentiate their function,can anyone helps me by any method, or use names of shape according to this site http://www.breezetree.com/article-excel-flowchart-shapes.htm

这些符号听起来太相似而无法区分它们的功能,任何人都可以通过任何方法帮助我,或根据此站点使用形状名称http://www.breezetree.com/article-excel-flowchart-shapes.htm

回答by Himanshu Tyagi

Flow chart

流程图



REF:参考:

Used a random online tool to generate this flowchart from your code. http://code2flow.com/

使用随机在线工具从您的代码生成此流程图。http://code2flow.com/

Study more about flowcharts here : http://creately.com/blog/diagrams/flowchart-guide-flowchart-tutorial/

在此处研究有关流程图的更多信息:http: //creately.com/blog/diagrams/flowchart-guide-flowchart-tutorial/

See sample flowcharts here : http://www.conceptdraw.com/samples/flowcharts

在此处查看示例流程图:http: //www.conceptdraw.com/samples/flowcharts

回答by Mike Ciaraldi

Back in the days of FORTRAN, we used that hexagonal symbol on the page you linked to for the "DO" loop, which is basically the same as the modern "for" loop.

回到 FORTRAN 时代,我们在您链接到的页面上使用六边形符号作为“DO”循环,这与现代的“for”循环基本相同。

So, to draw the loop part of your program I would use that symbol, with a note inside like this:
  for i = 0 --> (lines - 1)
Read this as "for i from 0 to (lines - 1)" with the increment of 1 implied by default. Then the bottom-most box in the loop would have two arrows coming out of it: one straight down to the next statement, and one out the side heading back up to the side of the hexagon.

因此,要绘制程序的循环部分,我将使用该符号,并在其中添加如下注释:
  for i = 0 --> (lines - 1)
将此读作“for i from 0 to (lines - 1)”默认情况下,增量为 1。然后循环中最底部的框将有两个箭头从它出来:一个直接向下到下一个语句,一个从一侧伸出,回到六边形的一侧。

You could use the diamond to represent "if", but that can obscure the meaning of what you are trying to do, namely execute the loop a certain number of times.

您可以使用菱形来表示“如果”,但这可能会掩盖您尝试执行的操作的含义,即执行一定次数的循环。

BTW, I don't have high enough reputation yet to post images, so you will have to either follow the link or visualize a hexagon whose center section has been stretched horizontally.

顺便说一句,我还没有足够的声誉来发布图像,因此您必须点击链接或可视化其中心部分已被水平拉伸的六边形。

Update: I see that, while I was typing my answer, thecbuilder has also answered this, with a real flowchart. His illustrates how the loop actually works internally, which is fine; mine was intended to show the meaning of the loop on a slightly higher level of abstraction.

更新:我看到,在我输入答案时,thecbuilder 也用真实的流程图回答了这个问题。他说明了循环实际上是如何在内部工作的,这很好;我的目的是在稍微更高的抽象级别上显示循环的含义。