在C:在单行文本文件阅读时分配变量 [英] In C: assigning variables when reading in a one-line text file
问题描述
我是编程新手。我一直在学习C,Fortran语言和Perl着急。我创建包含的表面情节网页的目标。我能够让我的程序通信完成这件事,但有我的变量在我的C程序中的分配问题。
I'm a beginning programmer. I've been learning C, Fortran, and Perl in a hurry. I have a goal of creating a webpage containing a surface plot. I am able to make my programs communicate to get this done, but have a problem with the assignment of my variables in my C program.
从我的Perl程序,我得到一个文本文件, data.in
只包含一行。
From my Perl program, I get a text file, data.in
which only contains one line.
例如: cosxtsiny 50 0.5 3 0 6
。这是我做了什么:
For example: cosxtsiny 50 0.5 3 0 6
. This is what I've done:
(声明我的变量字符
, INT
或双击
)
FILE *fi
fi = open("data.in", "r");
fscanf(fi, "%s %d %f %f %f %f", &func, &PTS, &xxa, &xxb, &yyc, &yyd);
close(fi);
我应该产生一个文件, data.out
,与价值观,我从获得 data.in
一旦我做一些计算它。这些将在以后产生曲面图我。
I'm supposed to produce a file, data.out
, with the values I get from data.in
once I do some calculations with it. These will later produce the surface plot for me.
下面是我的问题:我得到与gridpionts(PTS)的正确数量的表面图,所以我知道前两个任务是对的,但我的轴处于关闭状态。当我看到我的 data.out
,我的轴不开始和结束,他们都应该。有什么建议?
Here is my problem: I do get a surface plot with the correct amount of gridpionts (PTS) so I know the first two assignments are right, but my axes are off. When I see my data.out
, my axes don't start and end where they are supposed to. Any suggestions?
推荐答案
我想如果你在声明 FUNC
作为一个字符数组,那么你应该写类似的fscanf(FI,%S,FUNC)
而不是中的fscanf(FI,%S,&安培; FUNC)
I guess if you are declaring func
as a character array, then you should write something like fscanf(fi, "%s", func)
instead of fscanf(fi,"%s", &func)
.
这篇关于在C:在单行文本文件阅读时分配变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!