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
E

Eng zeyad

@Eng zeyad
About
Posts
4
Topics
1
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • threads ( c language ) in Ubunt
    E Eng zeyad

    i don't want to bother you ! ,

    C / C++ / MFC data-structures tutorial

  • threads ( c language ) in Ubunt
    E Eng zeyad

    #include
    <stdio.h>
    #include
    <stdlib.h>

    // The array that holds the data
    int array[1000]
    ;

    void testSum()
    {
    int sum=0;

    int j;

    for(j=0
    ; j< 1000 ; j++)

    {
    sum+=array[j];

    } 
    
       printf("Testing without threads, Sum is : %d \\n",sum); 
    

    }

    // This function reads a file with 1000 integers,
    an integer is stored in
    // each line.The function stores the integers in the array

    void readfile(char* file_name)

    {

    char ch;

    FILE *fp;

    fp = fopen(file_name,"r"); // read mode

    if( fp == NULL )
    {
    perror("Error while opening the file.\n");

     exit(EXIT\_FAILURE);
    

    }

    char line \[5\];
    

    /* line size */

    int i=0;
    

    printf("Reading file: ");

    fputs(file\_name,stdout);
    
    printf("\\n");
    
    
    while ( fgets ( line, sizeof line, fp) != NULL ) /\* read a line \*/
    {
       if (i < 1000)
       {
         array\[i\]=atoi(line); 
    
       }
    
        //debug code
        //fputs ( line, stdout ); /\* write the line \*/
      i++;
    

    }

    // debug code 
    //printf("i is : %d \\n",i);
    

    fclose(fp);

    printf("Reading file Complete, integers stored in array.\\n\\n"); 
    

    }

    int main(int argc, char* argv[])
    {

    if (argc != 2) {
    fprintf(stderr,"usage: a.out <file name>\n");

    /\*exit(1);
    

    */
    return -1;

    }

    readfile(argv[1]);

    //Debug code for testing only
    testSum();

    return 0;

    }

    C / C++ / MFC data-structures tutorial

  • threads ( c language ) in Ubunt
    E Eng zeyad

    my question is how to create an array using threads . i have posted all the code . but 1 thing is missing is how to implement thread in the array . regards

    C / C++ / MFC data-structures tutorial

  • threads ( c language ) in Ubunt
    E Eng zeyad

    how to program that uses 4 threads to compute the sum of an array of 1000 integers.

    C / C++ / MFC data-structures tutorial
  • Login

  • Don't have an account? Register

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