分割错误 - 没有想法为什么尝试我知道的少 [英] Segmentation Fault - No Idea Why Tried the Little I know

查看:50
本文介绍了分割错误 - 没有想法为什么尝试我知道的少的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是C编程的新手,我仍处于java和C#的早期阶段。我发布了关于我尝试运行我正在开发的程序时得到的分段错误错误代码。我在Ubuntu Linux计算机上编码,正在使用gcc进行编译。基本上程序应该做的是首先使用scanf()。它将从用户读入两个值到变量中,然后这些变量将被传递给一个方法,该方法将使用这些变量来发出system()。函数命令,它将使用从用户接受的参数来发出mplayer。命令到命令行。我已经尝试了所有我知道的解决问题的方法(基本上用%c代替%s)但是老实说我真的完全不知道为什么我在运行这个程序时会出现分段错误(在我读完用户的两个值后发生错误,所以我想我可能会错误地传递给方法,但实际上我只是不知道)。下面是我一直在谈论的程序的代码,如果你能发现导致分段错误的原因并向我解释,如果可能的话我怎么纠正它我会非常感激,我期待参与这个论坛。

I am new to C programming and am still at an early level in java and C#. I am posting regarding a segmentation fault error code I get when I try to run a program that I am developing. I am coding on an Ubuntu Linux computer and am compiling using gcc. Basically what the program is supposed to do is first using "scanf()" it will read in two values from the user into variables, and those variables will then be passed to a method which will use those variables to issue a "system()" function command which will use the arguments accepted from the user to issue an "mplayer" command to the command line. I have tried all that I know to fix the problem (which is basically substituting "%c" for "%s") but to be honest I really have absolutely no idea why I am getting a Segmentation Fault when I run this program(the error occurs after I have read in both values from the user, so I guess I could be passing to the method incorrectly, but really I just don''t know). Below is the code for the program I have been talking about, if you can spot what is causing the segmentation fault and explain it to me and if possible how I can correct it I would really appreciate it, I look forward to participating in this forum.

展开 | 选择 | Wrap | 行号

推荐答案


我是新来的C编程,我仍处于java和C#的早期阶段。我发布了关于我尝试运行我正在开发的程序时得到的分段错误错误代码。我在Ubuntu Linux计算机上编码,正在使用gcc进行编译。基本上程序应该做的是首先使用scanf()。它将从用户读入两个值到变量中,然后这些变量将被传递给一个方法,该方法将使用这些变量来发出system()。函数命令,它将使用从用户接受的参数来发出mplayer。命令到命令行。我已经尝试了所有我知道的解决问题的方法(基本上用%c代替%s)但是老实说我真的完全不知道为什么我在运行这个程序时会出现分段错误(在我读完用户的两个值后发生错误,所以我想我可能会错误地传递给方法,但实际上我只是不知道)。下面是我一直在谈论的程序的代码,如果你能发现导致分段错误的原因并向我解释,如果可能的话我怎么纠正它我会非常感激,我期待参与这个论坛。
I am new to C programming and am still at an early level in java and C#. I am posting regarding a segmentation fault error code I get when I try to run a program that I am developing. I am coding on an Ubuntu Linux computer and am compiling using gcc. Basically what the program is supposed to do is first using "scanf()" it will read in two values from the user into variables, and those variables will then be passed to a method which will use those variables to issue a "system()" function command which will use the arguments accepted from the user to issue an "mplayer" command to the command line. I have tried all that I know to fix the problem (which is basically substituting "%c" for "%s") but to be honest I really have absolutely no idea why I am getting a Segmentation Fault when I run this program(the error occurs after I have read in both values from the user, so I guess I could be passing to the method incorrectly, but really I just don''t know). Below is the code for the program I have been talking about, if you can spot what is causing the segmentation fault and explain it to me and if possible how I can correct it I would really appreciate it, I look forward to participating in this forum.
展开 | 选择 | Wrap | 行号


好吧,我尝试为Paul建议为每个变量分配内存,但现在我得到以下编译器错误:

Well, I tried allocating memory for each of the variables as Paul suggested, but now I get the following compiler errors:

展开 | 选择 | Wrap | 行号



好吧,我尝试为Paul建议为每个变量分配内存,但现在我得到以下编译器错误* snip *
Well, I tried allocating memory for each of the variables as Paul suggested, but now I get the following compiler errors *snip*
展开 | 选择 | 换行 | 行号


这篇关于分割错误 - 没有想法为什么尝试我知道的少的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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