473,320 Members | 1,845 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Help: how to read data file seperated by comma

Hi
Everybody,
I am confused for a few days, how to read the data file seperated by comma.
for exampe following file.
data.txt
1,2,3,4,5,6,7,8,9,10
11,12,13,14,15,16,17,18,19,20
how to read it inot an array or display them on screen?
thanks
Jan 22 '07 #1
3 8378
Ganon11
3,652 Expert 2GB
Are you using C++? If so, and you are using the ifstream class to read from the file, you can use the .ignore() function.

Since you know all your values are separated by commas, you can 1st read in the value (in your example integers) and then use .ignore(1) to skip the next character (the comma). If there are spaces in between the letters and the commas, you may have to use .ignore(100, ',') which will skip all characters until the comma.
Jan 22 '07 #2
horace1
1,510 Expert 1GB
Hi
Everybody,
I am confused for a few days, how to read the data file seperated by comma.
for exampe following file.
data.txt
1,2,3,4,5,6,7,8,9,10
11,12,13,14,15,16,17,18,19,20
how to read it inot an array or display them on screen?
thanks
if you are using C you can use scanf() so
Expand|Select|Wrap|Line Numbers
  1. scanf("%d,",&x); 
  2.  
where %d converts a decimal integer and the , checks that the next character in the input stream is a , and skips it
http://www.cplusplus.com/reference/clibrary/cstdio/scanf.html
Jan 22 '07 #3
Thanks for your help!!


if you are using C you can use scanf() so
Expand|Select|Wrap|Line Numbers
  1. scanf("%d,",&x); 
  2.  
where %d converts a decimal integer and the , checks that the next character in the input stream is a , and skips it
http://www.cplusplus.com/reference/clibrary/cstdio/scanf.html
Jan 22 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Jong Choi | last post by:
Dear All, I am trying to open the file(walk5.dat) and then read the data The structures of data are 0, 0, -10, -10, 0, -8.1,-12,-10 , 0,-14,-10,-7,0, 6.096666667,-10,-10,1, ...
5
by: Dr. Ann Huxtable | last post by:
Hello All, I am reading a CSV (comma seperated value) file into a 2D array. I want to be able to sort multiple columns (ala Excel), so I know for starters, I cant be using the array, I need...
8
by: baustin75 | last post by:
Posted: Mon Oct 03, 2005 1:41 pm Post subject: cannot mail() in ie only when debugging in php designer 2005 -------------------------------------------------------------------------------- ...
4
by: Jacob.Bruxer | last post by:
Hi, I'm pretty new to Visual Basic and was wondering if anyone could give some general advise on how to conserve memory when running a Visual Basic program that I've created. I keep getting a...
2
by: Peter | last post by:
Hello, I am having alot of trouble reading in a date values from a text file which is exported from another application. My program is pretty basic, I read in values from a plain text file...
13
by: anant | last post by:
Hi all The below code is reading string and then tokenizin it and reading all the info. But i want to call a csv file and it should then read a string from dt file. So what midification should i...
14
by: chance | last post by:
Hello, I have a file on disk called TEMP.ZIP and I would like to somehow get this into a memory stream so I can eventually do this: row = dataStream.ToArray() However, I am not sure of the...
4
nehashri
by: nehashri | last post by:
i want to knw how Search for text within single file in Ms Access, i have my data seperated by commas in the columns....... how do i query through the file for single word. like for example i want...
0
by: akshaycjoshi | last post by:
Most of you people are already familier with the working of crystal reports unlike me.I am working on an application when I have no other option but to use CR. It is very diff. for me to read an...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.