Find the answer to your Linux question:
Results 1 to 7 of 7
helo guzy .. well i m doing basic scripts ... plz help me in regards i use this thread for queries .. plz reply i write #include<stdio.h> #include<unistd.h> #include<stdlib.h> int ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Linux Newbie
    Join Date
    Feb 2005
    Posts
    137

    script help required error trace


    helo guzy .. well i m doing basic scripts ...

    plz help me in regards i use this thread for queries .. plz reply

    i write

    #include<stdio.h>
    #include<unistd.h>
    #include<stdlib.h>
    int main(int argc, char **argv)
    {

    int i, j;
    i=atoi(argv[1]);
    j=atoi(argv[2]);

    printf("%d",i+j);

    }


    named it as parm.c ... give it ... exe rights chmod 700 parm.c

    now run

    ./parm.c
    gives error ....

    ./parm.c: line 4: syntax error near unexpected token `('
    ./parm.c: line 4: `int main(int argc, char **argv)'


    what to do thnx for replying
    :: i dont know even a single word of linux ::

  2. #2
    Linux Newbie
    Join Date
    Oct 2004
    Posts
    158
    You have to compile it, then run the compiled executable file:
    Code:
    gcc -o parm  parm.c
    # this made a file called "parm" - that's what -o is for
    ./parm

    The ./ thing in front of the file name is to make the shell look for the parm file in your current directory.

  3. #3
    Linux Newbie
    Join Date
    Feb 2005
    Posts
    137

    thnx

    thnx for replying man although a dumb step i have missed ... anywayz thxn ..

    done ... all u said

    giving segmentation fault ... but it should produce .o file i think its not

    so ..
    :: i dont know even a single word of linux ::

  4. #4
    Linux Newbie eerok's Avatar
    Join Date
    Feb 2005
    Location
    Canada
    Posts
    153
    Code:
    #include<stdio.h>
    #include<unistd.h>
    #include<stdlib.h>
    
    int main&#40; int argc, char **argv &#41;
    &#123;
    
      if &#40; argv&#91;1&#93; && argv&#91;2&#93; &#41; &#123;
        int i = atoi&#40; argv&#91;1&#93; &#41;;
        int j = atoi&#40; argv&#91;2&#93; &#41;;
    
        printf&#40; "%d\n", i + j &#41;;
      &#125;
      else
        printf&#40; "%s\n", "Hey, we need 2 parms!" &#41;;
    &#125;
    noobus in perpetuum

  5. #5
    Linux Newbie
    Join Date
    Feb 2005
    Posts
    137

    solved

    thnx a lot problem solved i'll post other queries regarding scripts .. in this same thread .. thnx
    :: i dont know even a single word of linux ::

  6. #6
    scm
    scm is offline
    Linux Engineer
    Join Date
    Feb 2005
    Posts
    1,044
    If you call your C source code a "script", you're going to confuse people. A script is generally shorthand for "shellscript", a file containing commands that link together in some way to perform a more complex task.

  7. #7
    Linux Guru lakerdonald's Avatar
    Join Date
    Jun 2004
    Location
    St. Petersburg, FL
    Posts
    5,035
    Quote Originally Posted by scm
    If you call your C source code a "script", you're going to confuse people. A script is generally shorthand for "shellscript", a file containing commands that link together in some way to perform a more complex task.
    A script really just refers to a file written in any interpreted language, one of which C is most definitely not.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •