i don't want to bother you ! ,
Eng zeyad
Posts
-
threads ( c language ) in Ubunt -
threads ( c language ) in Ubunt#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 arrayvoid 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;
}
-
threads ( c language ) in Ubuntmy 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
-
threads ( c language ) in Ubunthow to program that uses 4 threads to compute the sum of an array of 1000 integers.