c program help

This is a discussion on c program help within the Linux Programming forums, part of the Platform Specific Boards category; hi all i have to write some script in c program i tried this Code: //cc simple.c -o simple #include ...

  1. #1
    Registered User
    Join Date
    Dec 2006
    Posts
    136

    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

  2. #2
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    You've got to escape the backslashes.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  3. #3
    Registered User
    Join Date
    Dec 2006
    Posts
    136
    Quote Originally Posted by CornedBee View Post
    You've got to escape the backslashes.
    how can i do?

    please help me

    thank you in advance

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    To get one backslash in a string, you need two backslashes, one to say "The next character is special, and the second to say 'I want a backslash'" - this is because backslash is already used as a "the next character is special", and the compiler needs the next char to say what special character you want (such as newline, backspace, or in this case a backslash).

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Issue with program that's calling a function and has a loop
    By tigerfansince84 in forum C++ Programming
    Replies: 9
    Last Post: 11-12-2008, 12:38 PM
  2. Need help with a program, theres something in it for you
    By engstudent363 in forum C Programming
    Replies: 1
    Last Post: 02-29-2008, 12:41 PM
  3. Replies: 4
    Last Post: 02-21-2008, 09:39 AM
  4. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21