LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-11-2003, 04:43 PM   #1
Linh
Member
 
Registered: Apr 2003
Posts: 178

Rep: Reputation: 30
Can 't compile because 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 }
==========================================
 
Old 06-11-2003, 04:49 PM   #2
kev82
Senior Member
 
Registered: Apr 2003
Location: Lancaster, England
Distribution: Debian Etch, OS X 10.4
Posts: 1,263

Rep: Reputation: 51
the \ character is a line break in a shell, it does not work in c. you can either put the whole string on one line or do it like this:

printf("This s"
"string is spl"
"it over lots "
"of lines.");
 
Old 06-11-2003, 05:17 PM   #3
Linh
Member
 
Registered: Apr 2003
Posts: 178

Original Poster
Rep: Reputation: 30
36) system(""/usr/suid/webofc/getdata | suid-to webofc ssh `grep "^10.0.0.1""
37) "/etc/hosts | head -n 1 | awk '{print $4}`' -C"
38) "suid putdata update && suid updatefirewall && suid updatemirrorhosts");
================================

root:~# gcc -o test1 test1.c
test1.c:38: unterminated string or character constant
test1.c:36: possible real start of unterminated constant

===============================

I even try this too where everything is in one line

36) 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");

test1.c: In function `main':
test1.c:36: malformed floating constant
test1.c:36: invalid operands to binary ^
test1.c:36: parse error before string constant
 
Old 06-11-2003, 05:52 PM   #4
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
You have double quotes ( " ) inside the string (in the grep command). And double quotes are also the delimiters of string (characters arrays) in C.
To have double quotes inside a string you have to use double double quotes. (In this case you could also use single quotes around the regexp in the grep command. single single quotes, or single back quotes are fine)

Summary of your program (also using the other tip kev82 mentioned, and with an error of swapped single quote and back quote fixed that your command has at the end of the awk command):
Code:
#include <stdlib.h>

int main ()
{
        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");
        return 0;
}

Last edited by Hko; 06-11-2003 at 05:56 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
convert string to long/int alaios Programming 10 09-15-2005 09:01 AM
How long does it take to compile the kernel on a slow machine? Shagrath239 Slackware 10 02-14-2005 11:11 PM
how to type this long command to compile a kde program? parv Programming 6 09-16-2004 05:00 PM
How long should it take to compile gcc? frankietomatoes Linux - General 2 05-08-2003 02:21 PM
How long does the mozilla compile? neo77777 General 11 07-04-2002 12:25 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:41 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration