<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Segmentation error with c program in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/segmentation-error-with-c-program/m-p/3884478#M67055</link>
    <description>"Segmentation violation" means your program is trying to access memory outside the areas reserved to it. With C programs, this usually means you've made some sort of error with pointer variables.&lt;BR /&gt;&lt;BR /&gt;You should check the number of command line arguments (int argc) before trying to read the argument strings (char **argv).&lt;BR /&gt;&lt;BR /&gt;The argv is an 1-dimensional array of pointers to strings (1-dimensional arrays of characters): its type can be expressed equivalently as  "char **argv", "char *argv[]" or "char argv[][]". I wouldn't recommend the last form though, because it easily leads you to think in the wrong way: argv definitely isn't a two-dimensional array, although it may seem somewhat like it.&lt;BR /&gt;&lt;BR /&gt;Normally, when you run a program without arguments, argc is usually 1. It means you'll have the name that was used to start the program in *argv[0]. If argc is equal to 1, you must not try to access *argv[1], because argv[1] is either NULL or random nonsense and trying to dereference either of those will produce the error message you're getting.&lt;BR /&gt;&lt;BR /&gt;In some special situations, the program can be started with argc equal to 0. Never just assume that you can read *argv[0] without checking the value of argc first.</description>
    <pubDate>Sun, 22 Oct 2006 11:58:57 GMT</pubDate>
    <dc:creator>Matti_Kurkela</dc:creator>
    <dc:date>2006-10-22T11:58:57Z</dc:date>
    <item>
      <title>Segmentation error with c program</title>
      <link>https://community.hpe.com/t5/operating-system-linux/segmentation-error-with-c-program/m-p/3884477#M67054</link>
      <description>Hi guys,&lt;BR /&gt;&lt;BR /&gt; I a writing a c program. but whenever try to run the file without arguments it will give segmentation. How can I catch this error before it terminate the progam. Thanks.&lt;BR /&gt;&lt;BR /&gt;Best regards&lt;BR /&gt;Henry</description>
      <pubDate>Sun, 22 Oct 2006 06:20:32 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/segmentation-error-with-c-program/m-p/3884477#M67054</guid>
      <dc:creator>Henry Chua</dc:creator>
      <dc:date>2006-10-22T06:20:32Z</dc:date>
    </item>
    <item>
      <title>Re: Segmentation error with c program</title>
      <link>https://community.hpe.com/t5/operating-system-linux/segmentation-error-with-c-program/m-p/3884478#M67055</link>
      <description>"Segmentation violation" means your program is trying to access memory outside the areas reserved to it. With C programs, this usually means you've made some sort of error with pointer variables.&lt;BR /&gt;&lt;BR /&gt;You should check the number of command line arguments (int argc) before trying to read the argument strings (char **argv).&lt;BR /&gt;&lt;BR /&gt;The argv is an 1-dimensional array of pointers to strings (1-dimensional arrays of characters): its type can be expressed equivalently as  "char **argv", "char *argv[]" or "char argv[][]". I wouldn't recommend the last form though, because it easily leads you to think in the wrong way: argv definitely isn't a two-dimensional array, although it may seem somewhat like it.&lt;BR /&gt;&lt;BR /&gt;Normally, when you run a program without arguments, argc is usually 1. It means you'll have the name that was used to start the program in *argv[0]. If argc is equal to 1, you must not try to access *argv[1], because argv[1] is either NULL or random nonsense and trying to dereference either of those will produce the error message you're getting.&lt;BR /&gt;&lt;BR /&gt;In some special situations, the program can be started with argc equal to 0. Never just assume that you can read *argv[0] without checking the value of argc first.</description>
      <pubDate>Sun, 22 Oct 2006 11:58:57 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/segmentation-error-with-c-program/m-p/3884478#M67055</guid>
      <dc:creator>Matti_Kurkela</dc:creator>
      <dc:date>2006-10-22T11:58:57Z</dc:date>
    </item>
  </channel>
</rss>

