Find the answer to your Linux question:
Results 1 to 5 of 5
hi all i have to write some script in c program i tried this Code: //cc simple.c -o simple #include <stdio.h> #include <stdlib.h> #include <string.h> int main(void) { char bb=system("cat ...
  1. #1
    Linux Newbie
    Join Date
    Feb 2007
    Location
    hyderabad, india
    Posts
    247

    c program help

    hi all
    i have to write some script in c program
    i tried this
    Code:
    //cc simple.c -o simple
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    
    int main(void)
    {
    
    char bb=system("cat file.txt | sed -n '/Underlying Value/,/]Top/p' | egrep -v 'Underlying Value|]Top' | sed 's/\[[0-9]\{1,\}\]//g' > /home/munna/Desktop/munna.txt");
    printf("******** %s \n",bb);
    
      return 0;
    }
    and the file.txt is
    [1]Home > [2]F&O >
    Watch

    All contracts of NIFTY
    As on Hours IST

    Instrument Type Underlying Expiry Date Option Type High
    Price Low Prev Close of contracts traded
    Turnover Lakhs Underlying Value

    [5]AAAAA [6]GGGGGG [7]25OC200 - - 5389.80 5203.10 5673.15 5255.00
    89085 234115.83 5143.90
    [8]AAAAA [9]GGGGGG [10]29NO2007 - - 5389.00 5211.00 5674.00 5269.95
    5265 13869.14 5143.90
    [11]BBBBBB [12]GGGGGG [13]25OC200 [14]CE [15]5600.00 74.00 15.00
    168.60 34.05 810 2281.01 5143.90
    [16]AAAAA [17]GGGGGG [18]27DE200 - - 5410.00 5125.00 5664.05 5265.00
    694 1828.64 5143.90

    [243]Top

    [1]http://www.google.com/
    [2]http://www.google.com/
    [7]http://www.google.com/
    [79]http://www.yahoo.com/
    [2447]http://www.google.com/
    [700]http://www.yahoo.com/
    but this program saying some errors like
    simple.c:9: warning: unknown escape sequence '\}'
    simple.c:9: warning: unknown escape sequence '\]'
    i wanna output in a string "bb".

    please help me

    thank you in advance
    "Relationships are built on trust and communication"

  2. #2
    Linux Guru Lakshmipathi's Avatar
    Join Date
    Sep 2006
    Location
    3rd rock from sun - Often seen near moon
    Posts
    1,568
    Code:
    char bb=system("cat file.txt | sed -n '/Underlying Value/,/]Top/p' | egrep -v 'Underlying Value|]Top' | sed 's/\[[0-9]\{1,\}\]//g' > /home/munna/Desktop/munna.txt");
    bb is an not an string array.
    Use string array.
    - Lakshmipathi.G
    -------------------
    FOSS India Award winning ext3fs Undelete tool and tutorials www.giis.co.in
    First they criticize you,Then they laugh at you,Then they fight with you,Then you win. - M.K.Gandhi
    -------------------

  3. #3
    Linux Newbie
    Join Date
    Feb 2007
    Location
    hyderabad, india
    Posts
    247
    Quote Originally Posted by Lakshmipathi View Post
    Code:
    char bb=system("cat file.txt | sed -n '/Underlying Value/,/]Top/p' | egrep -v 'Underlying Value|]Top' | sed 's/\[[0-9]\{1,\}\]//g' > /home/munna/Desktop/munna.txt");
    bb is an not an string array.
    Use string array.
    it is ok...
    am asking about the errors..
    just compile the code , u may know the fault in the program...

    can you please correct my program (rewrite)

    thank you in advance
    "Relationships are built on trust and communication"

  4. #4
    Linux Guru Lakshmipathi's Avatar
    Join Date
    Sep 2006
    Location
    3rd rock from sun - Often seen near moon
    Posts
    1,568

    Smile

    you are getting warning not an error so try with string array.
    try adding another \ near { ...I'm not sure this is an root cause ,



    Code:
    system("cat file.txt | sed -n '/Underlying Value/,/]Top/p' | egrep -v 'Underlying Value|]Top' | sed 's/\[[0-9]\\{1,\\}\\]//g' > /home/munna/Desktop/munna.txt");
    - Lakshmipathi.G
    -------------------
    FOSS India Award winning ext3fs Undelete tool and tutorials www.giis.co.in
    First they criticize you,Then they laugh at you,Then they fight with you,Then you win. - M.K.Gandhi
    -------------------

  5. #5
    Linux Enthusiast likwid's Avatar
    Join Date
    Dec 2006
    Location
    MA
    Posts
    649
    I haven't tried to compile it, but your main problem is that system returns an exit status, not a string. If what you want is the contents of that output file to be inside your program, you'd run that system() then you would use fopen to open the file, and fread to get the contents into a character array.

Posting Permissions

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