Thread: Need Help with Count function

  1. #31
    Registered User
    Join Date
    Oct 2008
    Location
    TX
    Posts
    2,059
    Pass "-v" option to gcc and post its output, as in:
    Code:
    gcc -v

  2. #32
    Registered User
    Join Date
    Mar 2009
    Posts
    31
    Reading specs from /usr/lib/gcc-lib/i386-linux/2.95.4/specs
    gcc version 2.95.4 20011002 (Debian prerelease)

  3. #33
    Registered User
    Join Date
    Oct 2008
    Location
    TX
    Posts
    2,059
    I don't have gcc so I can't help you out further and the vendor-supplied compiler is giving me right results.

  4. #34
    Registered User
    Join Date
    Mar 2009
    Posts
    31
    Quote Originally Posted by itCbitC View Post
    I don't have gcc so I can't help you out further and the vendor-supplied compiler is giving me right results.
    Is there a way I can use this vendor supplied compiler?

  5. #35
    Registered User
    Join Date
    Mar 2009
    Posts
    31
    Could anyone tell me what the compiler is?

  6. #36
    Registered User
    Join Date
    Oct 2008
    Location
    TX
    Posts
    2,059
    You can purchase it from SGI, though I am not sure if it will work for your Debian Linux release ie x86 architecture.
    Check out their site for developers or give them a call for more information.
    Whatever you do don't end up purchasing a compiler that is not written for your target architecture.

  7. #37
    Registered User
    Join Date
    Mar 2009
    Posts
    31
    Alright one more thing about this code. I'm trying to get the parent to display the counts and the child to display its pid but when I editted it nothing shows on the screen.

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <unistd.h>
    
    int main(void)
    {
        pid_t childpid;
        int count[2];
        int fd[2];
        int m;
    
        pipe(fd);
    
        if ((childpid = fork()) == -1) {
            perror("fork");
            exit(1);
        }
        else if (childpid == 0) {
            dup2(fd[0], 0);
            read(fd[0], count, sizeof count);
            printf("child process: this is my pid %d\n", getpid());
        }
        else if (childpid > 0) {
            //close(fd[0]);
            dup2(fd[1], 1);
            for (m = 0; m < 10001; m++) {
                if ((m%5) == 0)
                    count[0]++;
                if ((m%3) == 0)
                    count[1]++;
            }
          printf("child process: no. of multiples of 5 are %d"
                " and those of 3 are %d . The Pid is %d\n", count[0], count[1], getpid());
            
    write(fd[1], count, sizeof count);
        }
        return 0;
    }

  8. #38
    Registered User
    Join Date
    Oct 2008
    Location
    TX
    Posts
    2,059
    Because output of the parent is going into the pipe to the child process, so it won't be displayed on the terminal. Perhaps all you need is stdin and stdout without pipes.

  9. #39
    Registered User
    Join Date
    Mar 2009
    Posts
    31
    so you can communicate between processes using stdin and stdout?

  10. #40
    Registered User
    Join Date
    Oct 2008
    Location
    TX
    Posts
    2,059
    Quote Originally Posted by MSkiLLz View Post
    so you can communicate between processes using stdin and stdout?
    No they can't communicate with each other since there is no connection between them but they can write to stdout whenever scheduled to do so. IIRC we went over this in the first few posts of this thread.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Seg Fault in Compare Function
    By tytelizgal in forum C Programming
    Replies: 1
    Last Post: 10-25-2008, 03:06 PM
  2. In over my head
    By Shelnutt2 in forum C Programming
    Replies: 1
    Last Post: 07-08-2008, 06:54 PM
  3. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM
  4. Replies: 4
    Last Post: 11-23-2003, 07:15 AM
  5. Replies: 5
    Last Post: 02-08-2003, 07:42 PM