Find the answer to your Linux question:
Page 2 of 2 FirstFirst 1 2
Results 11 to 13 of 13
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #11

    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
    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;
    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:

     * 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" ); */
      for(i=0;i<argc;i++) iSum+=atoi(argv[i]);
      printf("%d\n", iSum);
      exit (0);
    and this is the script shell:

    sum=$(./myprogram $a $b)
    echo "Sum of $a,$b is $sum"
    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 "./"

    Hope this help.

  3. #13
    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

Posting Permissions

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