Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
E

Endomlic

@Endomlic
About
Posts
6
Topics
2
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • A better explanation on pipes, parents, and childs and tips to code
    E Endomlic

    I was given a HW assignment that I am having a lot of trouble on. I must have missed the day the teacher explained all of this because I have nothing on this material other than google...It's not even in the text. here is the problem Write a C-program that does the following: The program first creates a single pipe, using the pipe() system call. It then forks a child process using the fork() call. The goal is to share the work of counting numbers that are multiples of 3 and 5 from the set of integers from 1-10000. The parent process executes the for-loop (from 1-10000) and takes the responsibility for counting all multiples of 5. All numbers that are not multiple of 5 are passed through the pipe to the child process to be inspected and counted if they are multiples of 3. Note: Only the parent process will implement the for-loop from 1-10000. After the processes have completed their work, both, parent and child will print out a corresponding message together with their corresponding process-id. The child then uses the pipe to send its result to the parent. Upon reading the number of multiples of 3 from the pipe, the parent will print out the complete response to the user (i.e., count of multiples of 3 and 5) and wait for the child to exit properly and exit. What happens if the child process is executing significantly slower than the parent process, i.e., what if the parent wants to read from the pipe while the child process has not had a chance to read all multiples of 3 from it? Describe the problem! Describe how you simulated this problem! What do you need to do to avoid this problem? Show your solution! could anyone give me any ideas on how to go about solving this, and how I'm supposed to work with communicating these pipes?

    Linux, Apache, MySQL, PHP help tutorial question

  • An 'If' statement before my char declaration is not allowing my program to compile......why?
    E Endomlic

    Yay I got it to work! It was char* buff; if statement; buff = (char*) malloc( sizeof(char) * atoi( argv[1] ) ); Apparently I had to use argv 1 instead of 2. I guess in gcc argv 0 is the program name. Thanks to you guys for all the help!!

    C / C++ / MFC question help

  • An 'If' statement before my char declaration is not allowing my program to compile......why?
    E Endomlic

    I've tried that, but it acts as if it's not assigning buff with a size. in other words it's not working.

    C / C++ / MFC question help

  • An 'If' statement before my char declaration is not allowing my program to compile......why?
    E Endomlic

    yea, how do I do it using malloc :O

    C / C++ / MFC question help

  • An 'If' statement before my char declaration is not allowing my program to compile......why?
    E Endomlic

    If I declare the char beforehand then I can't use the if statement as intended. I need to see if they actually entered a buffer size, if not then the program will crash with the wrong error message I want displayed. That's where the if statement comes in. The if will break the program if they do not specify a buffer size. and if they do then it will be used as the char buff array size. How else can I declare a char buffer size and change it after the if?

    C / C++ / MFC question help

  • An 'If' statement before my char declaration is not allowing my program to compile......why?
    E Endomlic

    When I try to compile my code I get this error message: @: gcc -o hw3 hw3.c hw3.c: In function `main': hw3.c:20: parse error before `char' hw3.c:31: `buff' undeclared (first use in this function) hw3.c:31: (Each undeclared identifier is reported only once hw3.c:31: for each function it appears in.) The error occurs because of my if statement. When I place the if statement after the char declaration it works, also when I remove the if statement it compiles and works fine. if(argc == 1){ printf("Error: hw3 "); return 1; } Also for a plain "if(){}" as well. How do I get around this?

    #include
    #include
    #include
    #include

    int main(int argc, char * argv[])
    {
    //our file references and read and write counts
    int fileread, filewrite;
    ssize_t nread, nwrite;

    if(argc == 1){
    	printf("Error: hw3 ");
    	return 1;
    }
    
    //our buffer size is determined by the user
    char buff\[ (int)argv\[2\] \];
    
    // open 128kB file for reading
    // create if it doesn't exist copy.bmp for writing
    fileread = open("128kB.bmp", O\_RDONLY);
    filewrite = creat("copy.bmp", O\_WRONLY);
    
    //copy all of the contents of the file	
    while(1)
    {
    	//read data from the input file and place in the buffer
    	nread = read(fileread, buff, sizeof(buff) );
    
    	//if no information left to read, exit while loop
    	if (nread == 0) break;
    
    	//write the data from the buffer into the output file
    	nwrite = write(filewrite, buff, sizeof(buff) - 1 );
    }
    
    //close the files
    close(fileread);
    close(filewrite);
    
    return 0;
    

    }

    I am using a putty terminal connected to a unix machine.

    C / C++ / MFC question help
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups