Find the answer to your Linux question:
Page 2 of 2 FirstFirst 1 2
Results 11 to 13 of 13
yeah i had also lesson of C and C# in my 1st and 2nd semesters in university..but somehow i am not that good in programming...but i want to learn by ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #11
    Just Joined!
    Join Date
    Oct 2011
    Posts
    34

    yeah i had also lesson of C and C# in my 1st and 2nd semesters in university..but somehow i am not that good in programming...but i want to learn by hard to be a better programmer..anyways thanks for all information..

  2. #12
    Just Joined!
    Join Date
    Sep 2008
    Posts
    22
    Quote Originally Posted by nikhidet View Post
    thanks for the quick reply...i did try these code similar to yours for many times but it does not work...

    so could u take a look at my code maybe there is something wrong with it..
    this is my c program called try.c:
    #include <stdio.h>
    int main()
    {
    int a,b,c;
    c=a+b;
    printf ("c=%d\n",c);
    return 0;
    }
    ...
    Can't work because you don't pass values in any way from your shell script.
    Just at demonstrative level, you should do something I show you now.
    This is a sample C source:

    Code:
    /*
     * It simply makes a sum from 2 params. or more
     */
    
    #include <stdio.h>
    #include <stdlib.h>
    
    
    main(int argc, char *argv[])
    {
      register int i;
      int iSum=0;
    
      if( argc<3 ) { /* ERROR: I just want at least 2 parameters */
        /* if I want to produce error output, uncomment the next line */
        /* puts( "Error: I nead at least 2 numeric values\n" ); */
        exit(1);
      }
    
      for(i=0;i<argc;i++) iSum+=atoi(argv[i]);
    
      printf("%d\n", iSum);
    
      exit (0);
    }
    and this is the script shell:

    Code:
    #!/bin/bash
    
    a=180
    b=300
    
    sum=$(./myprogram $a $b)
    
    echo "Sum of $a,$b is $sum"
    
    a=18
    b=55
    c=90
    d=100
    
    sum=$(./myprogram $a $b $c $d)
    
    echo "Sum of $a,$b,$c,$d is $sum"
    compile C source with "cc myprog.c -o myprogram" and shell script must be in the same folder. Start with "./shell.sh"

    Hope this help.
    Gabo

  3. #13
    Just Joined!
    Join Date
    Oct 2011
    Posts
    34
    thanks for ur reply...i have done it and it works really well. i found it yesterday..anyways thanks for the info

  4. $spacer_open
    $spacer_close
Page 2 of 2 FirstFirst 1 2

Posting Permissions

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