Reading global variables from .csv file. | Sololearn: Learn to code for FREE!
Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
Essayez une leçon gratuite
0

Reading global variables from .csv file.

Suppose I have .CSV file like this Name GPA Syam,9.7 Kumar,8.9 Anil,7.9 Suresh,8.7 Out put should come like this in .txt Suresh got 8.7 GPA Syam got 9.7 GPA Anil got 7.9 GPA Kumar got 8.9 GPA But in the program I will write only names ( before comma values) it should replace number ( after comma values) Ex. fprintf(fp2, "Syam got %f GPA", syam); Whatever write name here it should replace with after comma value (9.7) Ex. fprintf(fp2, "Average GPA of Syam and Kumar %f GPA", (syam+Kumar)/2); Note: I want to print in fp2 sum names only. Not all the names. It should like global variables. Before " , " global variable and after " , " global variable value. Please let me know, if anyone knows this solution.

18th Dec 2018, 12:58 PM
Syam Kumar
Syam Kumar - avatar
2 Réponses
+ 1
In the time it took you to write this post and describe the problem, you probably could have written 73% of the code... Anyways, please show your attempt first
18th Dec 2018, 2:51 PM
Anna
Anna - avatar
0
#include <stdio.h> #include <stdlib.h> #include <math.h> /* input.csv , I want to read global variables from .csv EX. float syam = 9.8 syam,9.8 kumar,8.6 suresh,8.5 anil,5.9 girish,8.2 satish,8.8 shashi,6.8 ravi,7.8 mohan,6.9 varma,5.8 priya,9.2 gowthami,6.8 swarna,7.3 pallavi,6.7 meera,8.8 */ //Total Students in the class // If required I will variable here with initial value 0 but variable value should read from .csv float syam = 0; float kumar = 0; float suresh = 0; float anil = 0; float girish =0; float satish =0; float shashi =0; float ravi =0; float mohan =0; float varma =0; float priya =0; float gowthami =0; float swarna =0; float pallavi =0; float meera =0; int main() { FILE *fp1 = fopen("input.csv", "r"); FILE *fp2 = fopen("Output.txt", "w"); while ((ch = fgetc(fp1)) != EOF); fputc(ch, fp2); //I want print sum student only in .txt file. fprintf(fp2, "Syam got %.2f GPA\n",syam); fprintf(fp2, "Girsh got %.2f GPA\n",girish); fprintf(fp2, "Kumar got %.2f GPA\n",kumar); fprintf(fp2, "Suresh got %.2f GPA\n",suresh); fprintf(fp2, "Syam & Kumar got %f GPA\n",syam+kumar); fprintf(fp2, "Average GPA of Anil,Ravi and Priya %.2f GPA\n",((anil+ravi+priya)/3)); return 0; /* Output should be like this. Output.txt Syam got 9.8 GPA Girsh got 8.2 GPA Kumar got 8.6 GPA Suresh got 8.5 GPA Syam & Kumar got 18.4 GPA Average GPA of Anil,Ravi and Priya 7.63 GPA */
18th Dec 2018, 3:52 PM
Syam Kumar
Syam Kumar - avatar