tags:

views:

122

answers:

4

I want to my manipulate Stdin, then Std* but some errs:

$ gcc testFd.c                                                                 
testFd.c:9: error: initializer element is not constant
testFd.c:9: warning: data definition has no type or storage class
testFd.c:10: error: redefinition of `fd'
testFd.c:9: error: `fd' previously defined here
testFd.c:10: error: `mode' undeclared here (not in a function)
testFd.c:10: error: initializer element is not constant
testFd.c:10: warning: data definition has no type or storage class
testFd.c:12: error: syntax error before string constant
$ cat testFd.c                                                                 
#include <stdio.h>
#include <sys/ioctl.h>

int STDIN_FILENO = 1;
// I want to access typed 
// Shell commands, dunno about the value:
unsigned long F_DUPFD;

fd = fcntl(STDIN_FILENO, F_DUPFD, 0);
fd = open("/dev/fd/0", mode);

printf("STDIN = %s", fd);

Updated Errs: just trying to get an example program about file descriptors to work in C, pretty lost with the err report

$ cat testFd.c                                                                
#include <stdio.h>
#include <sys/ioctl.h>

int main (void) {
    int STDIN_FILENO;
    // I want to access typed 
    // Shell commands, dunno about the value:
    unsigned long F_DUPFD;
    int fd;
    const char mode = 'r';

    fd = fcntl(STDIN_FILENO, F_DUPFD, 0);
    /* also, did you mean `fopen'? */
    fd = fopen("/dev/fd/0", mode);

    printf("STDIN = %s", fd);

    return 0;
}
$ gcc testFd.c                                                                
testFd.c: In function `main':
testFd.c:14: warning: passing arg 2 of `fopen' makes pointer from integer without a cast
testFd.c:14: warning: assignment makes integer from pointer without a cast
+2  A: 

You forgot your main() function!!

Artelius
+2  A: 

Where's your definition of main()?

crazyscot
+3  A: 

Try using a main method:

#include <stdio.h>
#include <sys/ioctl.h>

int main (void) {
    int STDIN_FILENO = 1;
    // I want to access typed 
    // Shell commands, dunno about the value:
    unsigned long F_DUPFD;
    /* also, declare the type of your variable "fd" */
    int fd;

    fd = fcntl(STDIN_FILENO, F_DUPFD, 0);
    /* also, did you mean `fopen'? */
    fd = open("/dev/fd/0", mode);

    printf("STDIN = %s", fd);

    return 0;
}
amphetamachine
+2  A: 

Quite apart from the fact that you don't have a main() function, your entire approach is wrong. STDIN_FILENO is a constant; assigning to it doesn't make any sense.

Try explaining what you actually want to do, with some detail, and we will be able to suggest how to go about it.

caf
Yeah, there was a lot I didn't get to in my answer, mainly because I was confused as to what the OP was trying to do.
amphetamachine