Write a C program which reads and access the elements of the csv file by using the system call functions such as read, write and open. You should sum all the no. present inside a particular column in that csv file by using the words pthread_create and pthread_join only .
#include <stdio.h>
#include <stdlib.h>
int main(){
int sum1=0;
FILE *file;
file = fopen("myFile.csv", "r");
int arr[50];
int i;
if (file == NULL){
printf("\nError");
exit (0);
}
for (i = 0; i < 10; i++){
fscanf(file, "%d,", &arr[i] );
}
for (i = 0; i < 10; i++){
sum1=sum1+(arr[i]);
}
fclose(file);
printf("\nSum is: %d", sum1);
return 0;
}
Comments
Leave a comment