基础建设+2 [英] elementary construction +2

查看:88
本文介绍了基础建设+2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在确定如何最好地从

另一个调用已编译的c程序。以下是编译和显示信息的程序

通过:

//Text1.cpp


#include< stdio.h>


int main(int argc,char * argv [])

{

int i;
= i; i< = argc; i ++)

printf("%d \ t%s \ n" [i]);

返回(0);

}


以下是我第一次尝试调用此程序

模仿K&R§5.10。它编译,但我的链接器不喜欢它。我把它作为一个单独的项目中的
并硬编码路径吗?有没有比系统调用更好的方式来获得这个?b $ b?我只是忘了它,然后去做我的

指甲吗? MPJ


//text2.cpp


#include< stdio.h>

#include< stdlib.h>


int main(int orange,char * apple [])

{

system(" Text1水果飞行荷兰人);

返回(0);

}

I am determining how best to call an already compiled c program from
another. The following is a program that compiles and shows the information
passed:
//Text1.cpp

#include <stdio.h>

int main(int argc, char* argv[])
{
int i;

for (i=0;i<=argc;i++)
printf("%d\t%s\n",i,argv[i]);
return (0);
}

The following was my first attempt to call this program with something that
mimicks K&R §5.10. It compiles, but my linker didn''t like it. Do I put it
in a separate project and hard code the path? Is there a better way to go
about this than a system call? Do I just forget about it and go get my
nails done? MPJ

//text2.cpp

#include <stdio.h>
#include <stdlib.h>

int main(int orange, char* apple[])
{
system("Text1 fruit flying Dutchmen");
return (0);
}

推荐答案

"美林&米歇尔" <是******** @ comcast.net>写道:
"Merrill & Michele" <be********@comcast.net> wrote:
我正在确定如何最好地从另一个调用已编译的c程序。以下是编译和显示传递的信息的程序:
//Text1.cpp


这很可能不是作为C程序编译的,而是作为一个C ++程序。

小心嗤之以鼻;语言不一样。

#include< stdio.h>

int main(int argc,char * argv [])
{
int i;

for(i = 0; i< = argc; i ++)
printf("%d \ t%s \ n",i,argv [一世]);


这是错误的。你打印的是argv [argc]的内容,但是

argv [argc]必须是一个空指针,所以它没有内容,并且

最后一次通过循环运行的printf()说明符调用

未定义的行为。

你想要的是:


for(i = 0; i< argc; i ++)

printf("%d \ t%s \ n",i,argv [i]);

return(0);
}

以下是我第一次尝试用这个程序调用这个程序来模仿K&R§5.10。它编译,但我的链接器不喜欢它。


这不是很有帮助。 _How_你的链接器不喜欢它吗?大概是

它提供了比E042 - 代码太丑以至于链接更有用的错误消息。

//text2.cpp

#包括< stdio.h>
#include< stdlib.h>
int main(int orange,char * apple [])
{
system( Text1 fruit flying Dutchmen);
返回(0);
}
I am determining how best to call an already compiled c program from
another. The following is a program that compiles and shows the information
passed:
//Text1.cpp
This is most likely not compiled as a C program, but as a C++ program.
Beware the snark; the languages are not the same.
#include <stdio.h>

int main(int argc, char* argv[])
{
int i;

for (i=0;i<=argc;i++)
printf("%d\t%s\n",i,argv[i]);
This is wrong. You''re printing the contents of argv[argc], but
argv[argc] is required to be a null pointer, so it has no contents, and
the last printf() specifier of the last run through the loop invokes
undefined behaviour.
What you want is this:

for (i=0; i<argc; i++)
printf("%d\t%s\n", i, argv[i]);
return (0);
}

The following was my first attempt to call this program with something that
mimicks K&R §5.10. It compiles, but my linker didn''t like it.
That''s not very helpful. _How_ did your linker not like it? Presumably
it gave a more useful error message than "E042 - Code too ugly to link".
//text2.cpp

#include <stdio.h>
#include <stdlib.h>

int main(int orange, char* apple[])
{
system("Text1 fruit flying Dutchmen");
return (0);
}




除了C ++文件名(如果想要你的话)选择了nits,

不必要#include< stdio.h>以及main()的参数的愚蠢名称

(虽然我认为后者是故意的) ),我认为

这个程序没问题。


Richard



Apart from the C++ filename (and, if want your nits picked, the
unnecessary #include <stdio.h> and the silly names of main()''s arguments
(though I presume the latter was intentional)), I see no problem with
this program.

Richard


Merrill& Michele写道:
Merrill & Michele wrote:

我正在确定如何最好地从另一个调用已编译的c程序。以下是编译并显示传递的信息的程序:
//Text1.cpp
^^^^^^^^^

[.. 。] //text2.cpp

I am determining how best to call an already compiled c program from
another. The following is a program that compiles and shows the information
passed:
//Text1.cpp ^^^^^^^^^
[...] //text2.cpp



^^^^^^^^^

[...]


我想你想要comp.lang.c ++,它位于大厅和左边。


-

+ ---- --------------------- + -------------------- + ------- ---------------------- +

| Kenneth J. Brody | www.hvcomputer.com | |

| kenbrody / at\spamcop.net | www.fptech.com | #include< std_disclaimer.h> |

+ ------------------------- + -------------- ------ + ----------------------------- +


^^^^^^^^^
[...]

I think you want comp.lang.c++, which is down the hall and to the left.

--
+-------------------------+--------------------+-----------------------------+
| Kenneth J. Brody | www.hvcomputer.com | |
| kenbrody/at\spamcop.net | www.fptech.com | #include <std_disclaimer.h> |
+-------------------------+--------------------+-----------------------------+


Merrill& Michele写道:
Merrill & Michele wrote:
我正在确定如何最好地从另一个调用已编译的c程序。以下是编译和显示传递的信息的程序:
//Text1.cpp


大多数C实现编译源文件

名称以.c结尾(虽然C语言标准确实

不要求这个)。名称以.cpp结尾对于包含C ++的源文件经常使用

,这是一种完全不同的语言

与C表面有一些相似之处。通过调用你的

文件 Text1.cpp"你可能无意中告诉你的
编译器需要C ++源代码,如果你想写C,这可能会造成混乱。请仔细检查你的

设置以确保它正在按照你的意图行事。

#include< stdio.h>

int main(int argc, char * argv [])
{
int i;

for(i = 0; i< = argc; i ++)
printf("%d \\ \\t%s\\\
",I,的argv [1]);


此循环的最终执行产生未定义的

行为,因为`argv [argc]''保证为NULL。

当您将NULL传递给%s时说明者,没有

告诉可能会发生什么。建议修复:重新检查

循环的结束条件,并考虑如何更改

以避免此问题。

return (0);


你知道括号虽然无害,但是没必要,对吗?好。

}

以下是我第一次尝试用这个模拟K&R§5.10的方式来调用这个程序。它编译,但我的链接器不喜欢它。


当您向

内容或导入的错误消息寻求帮助时,请提供

消息的确切和完整的文本。 我的链接器

不喜欢它并不是非常有用,并且需要

读者来猜测发生了什么。二十个问题永远不会是我最喜欢的游戏。


我的猜测是你的链接器很喜欢它,并且

你错误地报告了什么问题。


哦,顺便说一句:*我的*链接器不喜欢萝卜。

我是把它放在一个单独的项目中并硬编码路径?有没有比系统调用更好的方式来解决这个问题?我只是忘了它,然后去做我的指甲吗? MPJ


项目?看起来你的问题可能根本就不是使用

C语言,而是使用你的

实现来实现它的咒语。如果是这样,你需要帮助来自新闻组或其他论坛的人们熟悉你的b / b
开发环境(无论是什么)。我们在这里可以做的所有事情都可以帮助你解决C问题;得到

C在System X或System Y或System Z上正确执行

不是我们的强项。


获取你的做完指甲似乎是一个好主意:它会让它变得更容易扯掉你的头发。

//text2.cpp

#include< stdio.h>
#include< stdlib.h>

int main(int orange,char * apple [])
{
system(Text1 fruit flying Dutchmen);


一个可能 - 甚至可能 - 困难的来源

是虽然system()本身是一个标准库

函数,其参数字符串'的含义是实现 -

具体。根据您的平台,您可能需要一个

系统()参数,例如


" ./ Text1 fruit flying Dutchmen"

.. \\Project1 \\Text1水果飞行的荷兰人

MCR TEXT1水果飞行的荷兰人


...或许咒语更奇怪。再次,

这是你的系统X / Y / Z朋友的问题,而不是C语言人员的问题。

返回(0 );;
}
I am determining how best to call an already compiled c program from
another. The following is a program that compiles and shows the information
passed:
//Text1.cpp
Most C implementations compile source files whose
names end in ".c" (although the C language Standard does
not require this). Names ending in ".cpp" are often used
for source files containing C++, a quite different language
with some superficial similarities to C. By calling your
file "Text1.cpp" you may inadvertently have told your
compiler to expect C++ source, and this is likely to create
confusion if you''re trying to write C. Double-check your
setup to make sure it''s doing what you intend.
#include <stdio.h>

int main(int argc, char* argv[])
{
int i;

for (i=0;i<=argc;i++)
printf("%d\t%s\n",i,argv[i]);
The final execution of this loop produces undefined
behavior, because `argv[argc]'' is guaranteed to be NULL.
When you pass NULL to the "%s" specifier, there''s no
telling what might happen. Suggested fix: Re-examine
the ending condition for the loop, and consider how it
might be changed to avoid this problem.
return (0);
You know that the parentheses, though harmless, are
unnecessary, right? Good.
}

The following was my first attempt to call this program with somethingthat
mimicks K&R §5.10. It compiles, but my linker didn''t like it.
When you ask for help with an error message whose
content or import you don''t understand, please supply
the exact and complete text of the message. "My linker
didn''t like it" isn''t very informative, and requires the
reader to guess what happened. Twenty Questions was never
my favorite game.

My guess is that your linker liked it just fine, and
that you''ve mis-reported what went wrong.

Oh, and by the way: *my* linker doesn''t like turnips.
Do I put it
in a separate project and hard code the path? Is there a better way togo
about this than a system call? Do I just forget about it and go get my
nails done? MPJ
"Project?" It seems your problem may not be with the
C language at all, but with the incantations that get your
implementation to do its thing. If so, you need help from
a newsgroup or other forum where people familiar with your
development environment (whatever it is) hang out. All we
can do here is help you with the C questions; getting the
C to execute correctly on System X or System Y or System Z
is not our forté.

Getting your nails done seems a good idea: it''ll make it
easier to tear your hair out.

//text2.cpp

#include <stdio.h>
#include <stdlib.h>

int main(int orange, char* apple[])
{
system("Text1 fruit flying Dutchmen");
One possible -- or even likely -- source of difficulty
is that although system() itself is a Standard library
function, its argument string''s meaning is implementation-
specific. Depending on your platform, you might need a
system() argument like

"./Text1 fruit flying Dutchmen"
"..\\Project1\\Text1 fruit flying Dutchmen"
"MCR TEXT1 FRUIT FLYING DUTCHMEN"

... or perhaps an incantation even more bizarre. Again,
this is a question for your System X/Y/Z friends, not for
the C language folks.
return (0);
}




我的(虚弱的)怀疑是你试图同时学习两个C会产生很多困难以及集成开发环境

同时进出的b / b
。当出现问题时,您不会知道您的C是否存在问题,或者是否已经配置IDE的方式为
。我强烈*建议

你把IDE放在一边,直到你对C的掌握有所改善;

这将消除丰富的搞砸源,因此

简化了诊断过程。使用普通编辑器准备你的C源

,并从

命令行运行编译器 - 我建议你甚至应该避免使用

广泛可用的制造实用程序直到你至少要用b / b
编写带有多个源文件的程序。


祝你好运!


-
Er ********* @ sun.com



My (weakly founded) suspicion is that many of your
difficulties arise from trying to learn both C and the
ins and outs of an "integrated development environment"
at the same time. When something goes awry, you don''t
know whether there''s a problem with your C or with the
way the IDE has been configured. I''d *strongly* suggest
that you put the IDE aside until your grasp of C improves;
this will eliminate a rich source of screw-ups and thus
simplify the diagnostic process. Prepare your C source
with an ordinary editor, and run the compiler from the
command line -- I''d suggest you should even avoid the
widely-available "make" utility until you''re at least to
the point of writing programs with multiple source files.

Good luck!

--
Er*********@sun.com


这篇关于基础建设+2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆