Visit Our UNIX and Linux User Community

little program error.

Thread Tools Search this Thread
Top Forums Programming little program error.
# 1  
Old 11-18-2008
little program error.

I am trying to work this little program, its not working..

int main()

               FILE *fp;
               char *args[40];
               pid_t child, exited_pid;
               int status = 0;
               *args[0] = "less";
               fp = popen("ls", "r");
               child = fork();
               if(child == 0)
                      dup2(fp->fd, 0);
                      if(execvp(args[0], args) == -1)


I got error.
Warning: assignment makes integer from pointer without a cast
Error: 'FILE' has no member named 'fd'
Error: expected declaration or statement at end of input.

My whole goal of the program is to execute ls, and read from that program & store it in the buffer. Then my second program (argss[0]) reads the input coming from there and uses it...

help plzSmilie
# 2  
Old 11-18-2008
C: FILE Structure !, FILE structure in C

typedef struct  {
       int             level;      /* fill/empty level of buffer */
       unsigned        flags;      /* File status flags          */
       char            fd;         /* File descriptor            */
       unsigned char   hold;       /* Ungetc char if no buffer   */
       int             bsize;      /* Buffer size                */
  unsigned char   *buffer;    /* Data transfer buffer       */
  unsigned char   *curp;      /* Current active pointer     */
       unsigned        istemp;     /* Temporary file indicator   */
       short           token;      /* Used for validity checking */
}       FILE;

How come "FILE" has no member named fd
# 3  
Old 11-18-2008
FILE is opaque -- you're not supposed to mess with what's inside, because it might be different everywhere you go. It's like a system call, you aren't supposed to ask the kernel what's inside its file tables. Technically you can get the fd with fileno() but since any actions on fp after you mess with its raw file descriptor may be unpredictable, I'd suggest making a pipe(), forking, and redirecting through the pipe instead. That's how popen works anyhow.

Last edited by Corona688; 11-18-2008 at 04:49 PM..
# 4  
Old 11-18-2008
k thx
# 5  
Old 11-19-2008
This is wrrong too:
*args[0] = "less"

You have declared args to be an array of pointers to char, and "less" is a pointer to char, so you need
args[0] = "less"

Previous Thread | Next Thread
Test Your Knowledge in Computers #289
Difficulty: Easy
Sun Microsystems was acquired by Oracle Corporation in 2012.
True or False?

10 More Discussions You Might Find Interesting

1. Programming

Error in my FORTRAN program

I have a Fortran program and I am writing out to logical unit 7. The program is reading from a text file and writing to the new file formatted. It gets through the read and writes some to the file but then stops with the following error: 1525-013 The sequential WRITE statement cannot be... (5 Replies)
Discussion started by: KathyB148
5 Replies

2. Programming

Error in executing the C program

Hello Friends, I have written a code for the unisex bathroom which makes a policy that when a woman is in the bathroom only other women may enter, but not men, and vice versa. This program consists of four functions which a user defines but these functions are not properly working while... (4 Replies)
Discussion started by: Ravi Tej
4 Replies

3. Solaris

Shell program error!!!

Hello guys, This is an executable shell program that I want to execute, but it doesn't execute and gives error. The shell program that I want to execute is taken from a well-reputed book on Solaris 10. Here is the program #!/usr/bin/bash if test -a $1 then echo "Number of lines in file " $1... (2 Replies)
Discussion started by: gabam
2 Replies

4. Programming

An error in my c++ program... please help urgent.

The following is a program to convert an infix expression to postfix expression. //Convert an infix expression to postfix expression... #include<iostream> #include<string> #include<cstdlib> using namespace std; char ifx,pfx,stk; int top=-1,n; void push(char ch) { if(top!=n) ... (6 Replies)
Discussion started by: poonam.gaigole
6 Replies

5. Programming

Runtime error in C++ Program - Help

All, I am getting this when i try to ran a program in HP unix. Things i came across 1. i have a system HP-UNIX where this same exe is working. 2. We have set a new HP_UNIX with the same configration and copied the exe to the new system we are getting this error. 3. Only... (3 Replies)
Discussion started by: arunkumar_mca
3 Replies

6. Linux

an error in perl program

Hi I am having a file with 243 lines.. The file format s given below eg P25787 hsa03050 1 P20618 hsa03050 1 P25786 hsa03050 1 P49721 hsa03050 1 P54132 hsa03440 1 Q13472 hsa03470 1 Q05513 hsa04530 hsa04910 hsa04930 3 Q04759 ... (0 Replies)
Discussion started by: binnybio
0 Replies

7. Shell Programming and Scripting

Need help with program error

#!/bin/csh # # Time of day greeting # # usage: greet # if ($#argv == 0) then set hour = ‘date +%H’ else set hour = $argv endif # if ($hour < 12) then echo "Good Morning\!" else if ($hour < 18) then echo "Good Afternoon\!" ... (2 Replies)
Discussion started by: glock1800
2 Replies

8. Shell Programming and Scripting

Error in AWK Program

Hi Friends, I need your help. I am not able to execute one awk program .If you can solve the following small program then i can solve other one. $ vi prg #!/bin/awk -f BEGIN { # Print the squares from 1 to 10 the first way i=1; while (i <= 10) { ... (3 Replies)
Discussion started by: bikas_jena
3 Replies

9. AIX

Program Error

Hi, my IBM 9117-570 model (mounting SF230_126 firmware version) gives an errpt like the following. The problem is that no SRC code found at IBM information center web site. Some ideas where are those SRC searchable ? O.S. is AIX 5.2- tkx E18E984F 1119200506 P S SRC ... (0 Replies)
Discussion started by: Carmen123
0 Replies

10. Programming

Error Compiling C program

Hi All, I tried to compile a C program but i am getting error while Linking . it says Undefined reference to ' ' (here it gives a method name which is defined Globally ). Can any body tell the resaon and remedy for the same . Iam stuck up here . Thanks (3 Replies)
Discussion started by: Vivek
3 Replies

Featured Tech Videos