How can I read a float numbers which are in a text file using C [closed]
up vote
-3
down vote
favorite
The text file contains the text below, how to write a program to save it to a variable called 'a'?
Bank Rate(1) Rate(2) Rate(3)
A 1.11 1.52 1.26
B 3.22 4.24 5.25
C 1.68 7.68 7.2
D 3.26 4.23 1.7
c
New contributor
closed as too broad by paddy, Jonathan Leffler, Welcome to Stack Overflow, David C. Rankin, qrdl Nov 5 at 7:09
Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
add a comment |
up vote
-3
down vote
favorite
The text file contains the text below, how to write a program to save it to a variable called 'a'?
Bank Rate(1) Rate(2) Rate(3)
A 1.11 1.52 1.26
B 3.22 4.24 5.25
C 1.68 7.68 7.2
D 3.26 4.23 1.7
c
New contributor
closed as too broad by paddy, Jonathan Leffler, Welcome to Stack Overflow, David C. Rankin, qrdl Nov 5 at 7:09
Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
1
Well, you'd probably start by opening the file, using fscanf to read the number or numbers you want into the desired variables. Come back with some code; we'd be happy to help you further.
– Dan Farrell
Nov 5 at 3:16
Or even better, open the file and read each line into a buffer and than usestrtof
to step through the buffer picking out value (orsscanf
updating the pointer position following each conversion)
– David C. Rankin
Nov 5 at 4:41
Welcome to Stack Overflow. Please read the About page soon and also visit the links describing How to Ask a Question and How to create a Minimal, Complete, and Verifiable example. Providing the necessary details, including your code, compiler warnings and associated errors, if any, will allow everyone here to help you with your question.
– David C. Rankin
Nov 5 at 4:44
add a comment |
up vote
-3
down vote
favorite
up vote
-3
down vote
favorite
The text file contains the text below, how to write a program to save it to a variable called 'a'?
Bank Rate(1) Rate(2) Rate(3)
A 1.11 1.52 1.26
B 3.22 4.24 5.25
C 1.68 7.68 7.2
D 3.26 4.23 1.7
c
New contributor
The text file contains the text below, how to write a program to save it to a variable called 'a'?
Bank Rate(1) Rate(2) Rate(3)
A 1.11 1.52 1.26
B 3.22 4.24 5.25
C 1.68 7.68 7.2
D 3.26 4.23 1.7
c
c
New contributor
New contributor
edited Nov 5 at 4:37
Faraz
602413
602413
New contributor
asked Nov 5 at 3:13
JJ Tan
1
1
New contributor
New contributor
closed as too broad by paddy, Jonathan Leffler, Welcome to Stack Overflow, David C. Rankin, qrdl Nov 5 at 7:09
Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
closed as too broad by paddy, Jonathan Leffler, Welcome to Stack Overflow, David C. Rankin, qrdl Nov 5 at 7:09
Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
1
Well, you'd probably start by opening the file, using fscanf to read the number or numbers you want into the desired variables. Come back with some code; we'd be happy to help you further.
– Dan Farrell
Nov 5 at 3:16
Or even better, open the file and read each line into a buffer and than usestrtof
to step through the buffer picking out value (orsscanf
updating the pointer position following each conversion)
– David C. Rankin
Nov 5 at 4:41
Welcome to Stack Overflow. Please read the About page soon and also visit the links describing How to Ask a Question and How to create a Minimal, Complete, and Verifiable example. Providing the necessary details, including your code, compiler warnings and associated errors, if any, will allow everyone here to help you with your question.
– David C. Rankin
Nov 5 at 4:44
add a comment |
1
Well, you'd probably start by opening the file, using fscanf to read the number or numbers you want into the desired variables. Come back with some code; we'd be happy to help you further.
– Dan Farrell
Nov 5 at 3:16
Or even better, open the file and read each line into a buffer and than usestrtof
to step through the buffer picking out value (orsscanf
updating the pointer position following each conversion)
– David C. Rankin
Nov 5 at 4:41
Welcome to Stack Overflow. Please read the About page soon and also visit the links describing How to Ask a Question and How to create a Minimal, Complete, and Verifiable example. Providing the necessary details, including your code, compiler warnings and associated errors, if any, will allow everyone here to help you with your question.
– David C. Rankin
Nov 5 at 4:44
1
1
Well, you'd probably start by opening the file, using fscanf to read the number or numbers you want into the desired variables. Come back with some code; we'd be happy to help you further.
– Dan Farrell
Nov 5 at 3:16
Well, you'd probably start by opening the file, using fscanf to read the number or numbers you want into the desired variables. Come back with some code; we'd be happy to help you further.
– Dan Farrell
Nov 5 at 3:16
Or even better, open the file and read each line into a buffer and than use
strtof
to step through the buffer picking out value (or sscanf
updating the pointer position following each conversion)– David C. Rankin
Nov 5 at 4:41
Or even better, open the file and read each line into a buffer and than use
strtof
to step through the buffer picking out value (or sscanf
updating the pointer position following each conversion)– David C. Rankin
Nov 5 at 4:41
Welcome to Stack Overflow. Please read the About page soon and also visit the links describing How to Ask a Question and How to create a Minimal, Complete, and Verifiable example. Providing the necessary details, including your code, compiler warnings and associated errors, if any, will allow everyone here to help you with your question.
– David C. Rankin
Nov 5 at 4:44
Welcome to Stack Overflow. Please read the About page soon and also visit the links describing How to Ask a Question and How to create a Minimal, Complete, and Verifiable example. Providing the necessary details, including your code, compiler warnings and associated errors, if any, will allow everyone here to help you with your question.
– David C. Rankin
Nov 5 at 4:44
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
Open the file, read each line, and then scan for the floats. You can accomplish this quite easily. There are about a dozen similar questions dedicated directly to reading float numbers from files using C posted here.
Here are some similar questions on StackOverflow which you can use to help accomplish your task:
Read int OR float from file in C
How to read floats from file in c?
C - Read in float value using getchar and print out float using printf
Reading float using scanf in c
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
Open the file, read each line, and then scan for the floats. You can accomplish this quite easily. There are about a dozen similar questions dedicated directly to reading float numbers from files using C posted here.
Here are some similar questions on StackOverflow which you can use to help accomplish your task:
Read int OR float from file in C
How to read floats from file in c?
C - Read in float value using getchar and print out float using printf
Reading float using scanf in c
add a comment |
up vote
0
down vote
Open the file, read each line, and then scan for the floats. You can accomplish this quite easily. There are about a dozen similar questions dedicated directly to reading float numbers from files using C posted here.
Here are some similar questions on StackOverflow which you can use to help accomplish your task:
Read int OR float from file in C
How to read floats from file in c?
C - Read in float value using getchar and print out float using printf
Reading float using scanf in c
add a comment |
up vote
0
down vote
up vote
0
down vote
Open the file, read each line, and then scan for the floats. You can accomplish this quite easily. There are about a dozen similar questions dedicated directly to reading float numbers from files using C posted here.
Here are some similar questions on StackOverflow which you can use to help accomplish your task:
Read int OR float from file in C
How to read floats from file in c?
C - Read in float value using getchar and print out float using printf
Reading float using scanf in c
Open the file, read each line, and then scan for the floats. You can accomplish this quite easily. There are about a dozen similar questions dedicated directly to reading float numbers from files using C posted here.
Here are some similar questions on StackOverflow which you can use to help accomplish your task:
Read int OR float from file in C
How to read floats from file in c?
C - Read in float value using getchar and print out float using printf
Reading float using scanf in c
answered Nov 5 at 3:57
Faraz
602413
602413
add a comment |
add a comment |
1
Well, you'd probably start by opening the file, using fscanf to read the number or numbers you want into the desired variables. Come back with some code; we'd be happy to help you further.
– Dan Farrell
Nov 5 at 3:16
Or even better, open the file and read each line into a buffer and than use
strtof
to step through the buffer picking out value (orsscanf
updating the pointer position following each conversion)– David C. Rankin
Nov 5 at 4:41
Welcome to Stack Overflow. Please read the About page soon and also visit the links describing How to Ask a Question and How to create a Minimal, Complete, and Verifiable example. Providing the necessary details, including your code, compiler warnings and associated errors, if any, will allow everyone here to help you with your question.
– David C. Rankin
Nov 5 at 4:44