Menu
C Arrays Arrays are used to store multiple values in a single variable, instead of declaring separate variables for each value. To declare an array, define the variable type, specify the name of the array followed by square brackets and specify the number of elements it should store. Most of the libraries commonly used in C can't print arrays, per se. Auto-tune evo free download. You'll have to loop through it manually and print out each value. Printing arrays and dumping many different kinds of objects is a feature of higher level languages.
so all i want to so is read a txt file and store it into an array but im im having a difficulty and here is my code
and my txt file has a delimeter (',') so i put a getline function as well but it is not wrking for me please help.
the txt file is:
Substance, Molecular weight
Benzene, 78.115
Ethyl Alcohol, 46.07
Refrigerant R134a (tetraflouroethane), 102.3
and my txt file has a delimeter (',') so i put a getline function as well but it is not wrking for me please help.
the txt file is:
Substance, Molecular weight
Benzene, 78.115
Ethyl Alcohol, 46.07
Refrigerant R134a (tetraflouroethane), 102.3
- 3 Contributors
- forum 5 Replies
- 4,787 Views
- 1 Day Discussion Span
- commentLatest Postby tinstaaflLatest Post
tinstaafl1,114
From an examination of your code, a part of your problem appears to be using
index
to fill the array, but your loop is incrementing count
. Therefore the array is always using the same index.Also using
eof()
to terminate the loop is bad practise. Instead use the return value of getline. When getline can't read any more it will return false.:Checking if infile is valid after you've read to eof wil always rerturn 1. Check before the while loop.
You haven't got a loop to print out the data in the arrays.
Edited by tinstaafl
- Learn C By Examples Time
- C Programming Useful Resources
- Selected Reading
This program will let you understand that how to print an array in C. We need to declare & define one array and then loop upto the length of array. At each iteration we shall print one index value of array. We can take this index value from the iteration itself.
Algorithm
Let's first see what should be the step-by-step procedure of this program −
Pseudocode
Let's now see the pseudocode of this algorithm −
Implementation
The implementation of the above derived pseudocode is as follows −
Dev C Store Values And Print Array Number
The output should look like this −
Dev C Store Values And Print Array In Java
array_examples_in_c.htm