如何从.csv文件中获取输入值并在.txt文件中执行 [英] How to take input values from .csv file and execute in .txt file
问题描述
如何从.csv文件中获取输入值并在.txt文件中执行。
ex:
学生-1,500
学生-2,2
学生-3,800
fprintf(学生-1分数=%f,学生 - 1);
在这种情况下,我只会在,我的变量和,变量值之后。
请让我解释这个问题。
我尝试过:
学生-1,500
学生-2,2
学生-3,800
fprintf(学生-1标记=%f,学生1);
在这种情况下,我只会在,之前我的变量和,变量值之后。
how to take input values from .csv file and execute in .txt file.
ex:
Student-1, 500
Student-2, 200
Student-3, 800
fprintf("The Student-1 marks are = %f", Student-1);
In this condition i will take only before "," my variable and after "," variable value.
Please let me explain this problem.
What I have tried:
Student-1, 500
Student-2, 200
Student-3, 800
fprintf("The Student-1 marks are = %f", Student-1);
In this condition i will take only before "," my variable and after "," variable value.
推荐答案
读取csv文件的每一行。使用 strtok,_strtok_l,wcstok,_wcstok_l,_mbstok,_mbstok_l [ ^ ]。使用 atoi,_atoi_l,_wtoi,_wtoi_l 将第二个字符串转换为整数[ ^ ](不浮动,因为数据中的数字是整数)。打印结果。或者,如果您未在任何计算中使用该数字,则可以将该数字打印为字符串。
Read each line of the csv file. Split it into tokens using strtok, _strtok_l, wcstok, _wcstok_l, _mbstok, _mbstok_l[^]. Convert the second string to an integer using atoi, _atoi_l, _wtoi, _wtoi_l[^] (not float since the numbers in your data are integers). Print the results. Or you could print the number as a string if you are not using it in any calculations.
这篇关于如何从.csv文件中获取输入值并在.txt文件中执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!