can someone help me how to compile this program??

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Anarki

    #1

    can someone help me how to compile this program??

    The following is the program i am trying to compile

    //restrict.c
    #include <stdio.h>
    int main()
    {
    char arr[10] = "Qualifiers "
    char * restrict p = arr;
    int i = 0;
    for(; i < 10; ++i)
    printf("%c", arr[i]);
    return 0;
    }

    i am using cygwin in window xp SP2, my gcc version is 3.4.4

    how do i compile the above program?

    i tried using this

    gcc -c -std=c99 restrict.c

    but i get an error like this

    restrict.c: In function 'main':
    restrict.c:6: error: parse error before "char"

    can someone help me how to compile this program??
  • Ian Collins

    #2
    Re: can someone help me how to compile this program??

    Anarki wrote:
    The following is the program i am trying to compile
    >
    //restrict.c
    #include <stdio.h>
    int main()
    {
    char arr[10] = "Qualifiers "
    Missing semicolon.

    --
    Ian Collins.

    Comment

    • MisterE

      #3
      Re: can someone help me how to compile this program??

      char arr[10] = "Qualifiers "

      you are missing ;
      try:
      char arr[10] = "Qualifiers ";


      Comment

      • Anarki

        #4
        Re: can someone help me how to compile this program??

        On Oct 1, 1:31 pm, MisterE <mist...@no.ema il.okwrote:
           char arr[10] = "Qualifiers "
        >
        you are missing ;
        try:
        char arr[10] = "Qualifiers ";
        omg! i didnt see tht *** semicolon srry thread closed!

        Comment

        • Anarki

          #5
          Re: can someone help me how to compile this program??

          On Oct 1, 1:31 pm, Ian Collins <ian-n...@hotmail.co mwrote:
          Anarki wrote:
          The following is the program i am trying to compile
          >
          //restrict.c
          #include <stdio.h>
          int main()
          {
             char arr[10] = "Qualifiers "
          >
          Missing semicolon.
          >
          --
          Ian Collins.
          Thx to Ian Collins and MisterE

          Comment

          • Joachim Schmitz

            #6
            Re: can someone help me how to compile this program??

            Anarki wrote:
            The following is the program i am trying to compile
            >
            //restrict.c
            #include <stdio.h>
            int main()
            Better: int main(void)
            {
            char arr[10] = "Qualifiers "
            Others told you about the missig ; here, but as yet nobody mentioned that
            arr[10] is too short to hold the string "Qualifiers ". You need arr[11] to
            have enough space for the terminating '\0'.
            You could automate that by using arr[] = "Qualifiers "; but then may have to
            adjust your for loop.
            char * restrict p = arr;
            int i = 0;
            for(; i < 10; ++i)
            printf("%c", arr[i]);
            return 0;
            }
            >
            i am using cygwin in window xp SP2, my gcc version is 3.4.4
            >
            how do i compile the above program?
            >
            i tried using this
            >
            gcc -c -std=c99 restrict.c
            >
            but i get an error like this
            >
            restrict.c: In function 'main':
            restrict.c:6: error: parse error before "char"
            >
            can someone help me how to compile this program??
            Bye, Jojo


            Comment

            • James Kuyper

              #7
              Re: can someone help me how to compile this program??

              Joachim Schmitz wrote:
              Anarki wrote:
              >The following is the program i am trying to compile
              >>
              >//restrict.c
              >#include <stdio.h>
              >int main()
              >
              Better: int main(void)
              >
              >{
              >char arr[10] = "Qualifiers "
              >
              Others told you about the missig ; here, but as yet nobody mentioned that
              arr[10] is too short to hold the string "Qualifiers ". You need arr[11] to
              have enough space for the terminating '\0'.
              It's legal to use a string literal to initialize an array that is not
              big enough to hold the terminating '\0' (6.7.8p14). He does not use arr
              in any way that requires it, so why should he provide space to store it?
              You could automate that by using arr[] = "Qualifiers "; but then may have to
              adjust your for loop.
              >
              >char * restrict p = arr;
              >int i = 0;
              >for(; i < 10; ++i)
              >printf("%c", arr[i]);
              >return 0;
              >}

              Comment

              • Joachim Schmitz

                #8
                Re: can someone help me how to compile this program??

                James Kuyper wrote:
                Joachim Schmitz wrote:
                >Anarki wrote:
                <snip>
                >>char arr[10] = "Qualifiers "
                >>
                >Others told you about the missig ; here, but as yet nobody mentioned
                >that arr[10] is too short to hold the string "Qualifiers ". You need
                >arr[11] to have enough space for the terminating '\0'.
                >
                It's legal to use a string literal to initialize an array that is not
                big enough to hold the terminating '\0' (6.7.8p14). He does not use
                arr in any way that requires it, so why should he provide space to
                store it?
                It may be legal to do so and he might not use it in this program, but it is
                a common enough mistake to forget to allocate space for the terminating '\0'
                to make it worthwhile being mentioned, wouldn't you agree?

                Bye, Jojo


                Comment

                • James Kuyper

                  #9
                  Re: can someone help me how to compile this program??

                  Joachim Schmitz wrote:
                  James Kuyper wrote:
                  >Joachim Schmitz wrote:
                  >>Anarki wrote:
                  <snip>
                  >>>char arr[10] = "Qualifiers "
                  >>Others told you about the missig ; here, but as yet nobody mentioned
                  >>that arr[10] is too short to hold the string "Qualifiers ". You need
                  >>arr[11] to have enough space for the terminating '\0'.
                  >It's legal to use a string literal to initialize an array that is not
                  >big enough to hold the terminating '\0' (6.7.8p14). He does not use
                  >arr in any way that requires it, so why should he provide space to
                  >store it?
                  >
                  It may be legal to do so and he might not use it in this program, but it is
                  a common enough mistake to forget to allocate space for the terminating '\0'
                  to make it worthwhile being mentioned, wouldn't you agree?
                  Perhaps, but the mention should have been written in a way that
                  acknowledges the possibility that the knew precisely what he was doing.
                  The way you wrote it left the impression that his code was unambiguously
                  wrong. You said "too short" and "you need", when it was precisely big
                  enough for everything he was going to do with it, and he therefore did
                  not need to make the change that you suggested.

                  Comment

                  • Joachim Schmitz

                    #10
                    Re: can someone help me how to compile this program??

                    James Kuyper wrote:
                    Joachim Schmitz wrote:
                    >James Kuyper wrote:
                    >>Joachim Schmitz wrote:
                    >>>Anarki wrote:
                    ><snip>
                    >>>>char arr[10] = "Qualifiers "
                    >>>Others told you about the missig ; here, but as yet nobody
                    >>>mentioned that arr[10] is too short to hold the string
                    >>>"Qualifiers" . You need arr[11] to have enough space for the
                    >>>terminatin g '\0'.
                    >>It's legal to use a string literal to initialize an array that is
                    >>not big enough to hold the terminating '\0' (6.7.8p14). He does not
                    >>use arr in any way that requires it, so why should he provide space
                    >>to store it?
                    >>
                    >It may be legal to do so and he might not use it in this program,
                    >but it is a common enough mistake to forget to allocate space for
                    >the terminating '\0' to make it worthwhile being mentioned, wouldn't
                    >you agree?
                    >
                    Perhaps, but the mention should have been written in a way that
                    acknowledges the possibility that the knew precisely what he was
                    doing. The way you wrote it left the impression that his code was
                    unambiguously wrong. You said "too short" and "you need", when it was
                    precisely big enough for everything he was going to do with it, and
                    he therefore did not need to make the change that you suggested.
                    OK, point taken.

                    Bye, Jojo


                    Comment

                    • August Karlstrom

                      #11
                      Re: can someone help me how to compile this program??

                      Anarki wrote:
                      The following is the program i am trying to compile
                      >
                      //restrict.c
                      #include <stdio.h>
                      int main()
                      {
                      char arr[10] = "Qualifiers "
                      char * restrict p = arr;
                      int i = 0;
                      for(; i < 10; ++i)
                      printf("%c", arr[i]);
                      return 0;
                      }
                      >
                      i am using cygwin in window xp SP2, my gcc version is 3.4.4
                      >
                      how do i compile the above program?
                      >
                      i tried using this
                      >
                      gcc -c -std=c99 restrict.c
                      >
                      but i get an error like this
                      >
                      restrict.c: In function 'main':
                      restrict.c:6: error: parse error before "char"
                      >
                      can someone help me how to compile this program??
                      I would write the program as

                      #include <stdio.h>

                      int main(void)
                      {
                      char arr[] = "Qualifiers ";
                      int i;

                      for (i = 0; arr[i] != '\0'; i++) {
                      printf("%c", arr[i]);
                      }
                      printf("\n");

                      return 0;
                      }

                      or simply

                      #include <stdio.h>

                      int main(void)
                      {
                      puts("Qualifier s");

                      return 0;
                      }


                      August

                      Comment

                      • Martin Ambuhl

                        #12
                        Re: can someone help me how to compile this program??

                        Anarki wrote:
                        char arr[10] = "Qualifiers "
                        ^^^
                        missing ';', creating an error before
                        char * restrict p = arr;
                        ^^^^
                        'char'. This is what your diagnostic mesage says:
                        restrict.c:6: error: parse error before "char"
                        can someone help me how to compile this program??
                        Add the semi-colon. No magic invocation of the compiler will make your
                        errors disappear.

                        Comment

                        • Martin Ambuhl

                          #13
                          Re: can someone help me how to compile this program??

                          Joachim Schmitz wrote:
                          Anarki wrote:
                          >The following is the program i am trying to compile
                          >>
                          >//restrict.c
                          >#include <stdio.h>
                          >int main()
                          >
                          Better: int main(void)
                          >
                          >{
                          >char arr[10] = "Qualifiers "
                          >
                          Others told you about the missig ; here, but as yet nobody mentioned that
                          arr[10] is too short to hold the string "Qualifiers ".
                          It is not too short for this initialization. It is true thar arr is an
                          array of characters and not a string, but the program in no way assumes
                          a string.
                          You need arr[11] to
                          have enough space for the terminating '\0'.
                          Only if he needs a string, which he does not.
                          You could automate that by using arr[] = "Qualifiers "; but then may have to
                          adjust your for loop.
                          There is nothing in the loop needing adjusting.
                          >char * restrict p = arr;
                          >int i = 0;
                          >for(; i < 10; ++i)
                          >printf("%c", arr[i]);
                          >return 0;
                          >}
                          If you wanted to pick nits, you should have pointed out the failure to
                          end the last line of output with an end-of-line character, instead of an
                          imaginary "problem".

                          Comment

                          • Joachim Schmitz

                            #14
                            Re: can someone help me how to compile this program??

                            Martin Ambuhl wrote:
                            Joachim Schmitz wrote:
                            >Anarki wrote:
                            >>The following is the program i am trying to compile
                            >>>
                            >>//restrict.c
                            >>#include <stdio.h>
                            >>int main()
                            >>
                            >Better: int main(void)
                            >>
                            >>{
                            >>char arr[10] = "Qualifiers "
                            >>
                            >Others told you about the missig ; here, but as yet nobody mentioned
                            >that arr[10] is too short to hold the string "Qualifiers ".
                            >
                            It is not too short for this initialization. It is true thar arr is
                            an array of characters and not a string, but the program in no way
                            assumes a string.
                            >
                            >You need arr[11] to
                            >have enough space for the terminating '\0'.
                            >
                            Only if he needs a string, which he does not.
                            And all that has been said some 4 hours ago, by James Kuyper...
                            >You could automate that by using arr[] = "Qualifiers "; but then may
                            >have to adjust your for loop.
                            >
                            There is nothing in the loop needing adjusting.
                            Not in this particular case, but I said 'may', didn't I?
                            >>char * restrict p = arr;
                            >>int i = 0;
                            >>for(; i < 10; ++i)
                            >>printf("%c" , arr[i]);
                            >>return 0;
                            >>}
                            >
                            If you wanted to pick nits,
                            I did not, but apparently you do
                            you should have pointed out the failure to
                            end the last line of output with an end-of-line character, instead of
                            an imaginary "problem".
                            This problem wasn't the OP's, but it certainly isn't imaginary.

                            Bye, Jojo


                            Comment

                            • Keith Thompson

                              #15
                              Re: can someone help me how to compile this program??

                              August Karlstrom <fusionfile@gma il.comwrites:
                              Anarki wrote:
                              >The following is the program i am trying to compile
                              >//restrict.c
                              >#include <stdio.h>
                              >int main()
                              >{
                              > char arr[10] = "Qualifiers "
                              > char * restrict p = arr;
                              > int i = 0;
                              > for(; i < 10; ++i)
                              > printf("%c", arr[i]);
                              > return 0;
                              >}
                              >i am using cygwin in window xp SP2, my gcc version is 3.4.4
                              >how do i compile the above program?
                              >i tried using this
                              >gcc -c -std=c99 restrict.c
                              >but i get an error like this
                              >restrict.c: In function 'main':
                              >restrict.c:6 : error: parse error before "char"
                              >can someone help me how to compile this program??
                              >
                              I would write the program as
                              >
                              #include <stdio.h>
                              >
                              int main(void)
                              {
                              char arr[] = "Qualifiers ";
                              int i;
                              >
                              for (i = 0; arr[i] != '\0'; i++) {
                              printf("%c", arr[i]);
                              }
                              printf("\n");
                              >
                              return 0;
                              }
                              >
                              or simply
                              >
                              #include <stdio.h>
                              >
                              int main(void)
                              {
                              puts("Qualifier s");
                              >
                              return 0;
                              }
                              I wouldn't write a program for that at all; I'd type "echo Qualifiers"
                              at my shell prompt.

                              Any program that illustrates some particular point that's been trimmed
                              down enough to post here can (probably) be transformed into a program
                              with equivalent behavior that utterly fails to illustrate the original
                              point. Which misses the point.

                              --
                              Keith Thompson (The_Other_Keit h) kst-u@mib.org <http://www.ghoti.net/~kst>
                              Nokia
                              "We must do something. This is something. Therefore, we must do this."
                              -- Antony Jay and Jonathan Lynn, "Yes Minister"

                              Comment

                              Working...