Here is my input:
david 10 40 70
sam 9 45 31
miranda 10 20 50
zhang 10 26 41
I am trying to add all these numbers for each line and then print them out in terminal like this:
david 120
sam 85
etc...
how do I sum these numbers starting from the second word in a line? Here's my code for some context:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
FILE *fr;
char * line = NULL;
size_t len =0;
ssize_t read;
int main(int argc, char* argv[]){
fr = fopen(argv[1], "r");
if(fr==NULL){
exit(EXIT_FAILURE);
}
while ((read = getline(&line, &len, fr)) != -1){
printf("%s", line );
}
fclose(fr);
if (line){free(line);}
return 0;
}