The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
.
google unix.com



High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
C++ map program - Error message dhanamurthy High Level Programming 0 04-02-2008 06:57 PM
Error in AWK Program bikas_jena Shell Programming and Scripting 3 01-07-2008 02:30 PM
Program Error Carmen123 AIX 0 11-23-2006 07:20 AM
unix - c program sending error from DB to email chino_52284 Shell Programming and Scripting 2 04-28-2005 08:12 PM
Error Compiling C program Vivek High Level Programming 3 10-25-2001 11:13 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-18-2008
joey joey is offline
Registered User
  
 

Join Date: Nov 2008
Posts: 15
little program error.

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

Code:
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)
                             {
                                printf("error");
                               exit(EXIT_FAILURE);
                              }

                wait(&status);
                wait(&status);
}

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 plz
  #2 (permalink)  
Old 11-18-2008
joey joey is offline
Registered User
  
 

Join Date: Nov 2008
Posts: 15
C: FILE Structure !, FILE structure in C

Code:
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 (permalink)  
Old 11-18-2008
Corona688 Corona688 is offline
Registered User
  
 

Join Date: Aug 2005
Location: Saskatchewan
Posts: 1,928
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 (permalink)  
Old 11-18-2008
joey joey is offline
Registered User
  
 

Join Date: Nov 2008
Posts: 15
k thx
  #5 (permalink)  
Old 11-19-2008
spirtle spirtle is offline
Registered User
  
 

Join Date: Jun 2008
Location: Scotland
Posts: 150
This is wrrong too:
Code:
*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
Code:
args[0] = "less"
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 06:18 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0