#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Posts
    245
    Rep Power
    12

    Problem compiling when long string is involved


    On Line 29, all actual the codes is on one line, so no carriage return character (\) is there.

    On line 30, it ended with a carriage return character (\)
    On line 31, it ended with a carriage return character (\)

    ======================================
    root:~# gcc -o test1 test1.c
    test1.c: In function `main':
    test1.c:30: malformed floating constant
    test1.c:30: invalid operands to binary /
    test1.c:30: parse error before `suid'

    Line 30 is where the problem is

    ======================================
    1#include <stdio.h>
    2#include <stdlib.h>
    3#include <string.h>
    4#include <sys/types.h>
    5#include <sys/stat.h>
    6#include <unistd.h>

    7int main()

    8{

    9 FILE *file_pointer;
    10 int i = 0;
    11 char single_char;
    12 char word[15];
    13 int result = 99;

    14 file_pointer = popen("cat /etc/yellowbox/network-config|grep FIREWALLGROUP | awk '{print $1}'", "r");

    15 single_char = getc(file_pointer); /* read first character */
    16 while(!feof(file_pointer) && single_char != '\n')
    17 {
    18 word[ i ] = single_char;
    19 printf("i = %d %c\n", i, word[ i ]);
    20 i++;
    21 single_char = getc(file_pointer);
    22 }
    23 word[ i ] = '\0';

    24 printf("word = %s\n", word);
    25 result = strcmp (word, "FIREWALLGROUP=0");
    26 printf("result = %d\n", result);
    27 if (result == 0)
    28 {
    29 printf("the value of the array word match that of the literal
    FIREWALLGROUP=0\n");

    30 system("/usr/suid/webofc/getdata | suid-to webofc ssh
    `grep /"^10.0.0.1/" \
    31 /etc/hosts | head -n 1 | awk '{print $4}`' -C \
    32 /"suid putdata update && suid updatefirewall && suid updatemirrorhosts/"");
    33 }
    34 }
    ==========================================
  2. #2
  3. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,172
    Rep Power
    2222
    You should not need to quote the newlines with a backslash there; C can handle it now. And believe it or not, the way to concatenate string literals in C is to just place them next to each other, even if they are on the next line.

    I think that this might work for lines 30-32:
    Code:
    system("/usr/suid/webofc/getdata | suid-to webofc ssh"
                " `grep \"^10.0.0.1\" /etc/hosts | head -n 1 | "
                " awk '{print $4}`' -C \"suid putdata update && "
                " suid updatefirewall && suid updatemirrorhosts\"");
    Please note that in order to quote (AKA "escape") the double quotation marks inside of the string, we need to use the backslash, ie '\"'.

    Give that a shot.

IMN logo majestic logo threadwatch logo seochat tools logo