Hello,
I am trying to write a program where i have to read a CSV file(obtained by converting an excel file having only 1 column of integers) into an array and then to display the same array as another CSV file. I am using Turbo C++ 4.5.
I've tried, but since i am a beginner with this programming, i was unable to do it.
Any advice would be really helpful.

Thanks,
Anuroop

Recommended Answers

All 5 Replies

The first thing you need is to gather the right tools. In this case can you view the CSV file that you will be reading from by opening it in Notepad so you know that it is intact? Do you know how to open/create a file? Do you know the various variable types available to you in C++? Do you know about the various options available forreading into strings using getline()? If the file you are reading has numerical fields and you wish to do calculations using the numerical values do you know how to convert strings into numerical values? Do you know how to write native types (and user defined types if needed) to the screen (which will basically be the same way you write them to file)?

If you know all of that, then you can write the program without any major problems. If not, learn a given concept in a smaller program first and then try to use that experience to do what is needed with that concept in your program.

I would suggest getting a compiler from this century, then reading up on ifstream.

The first thing you need is to gather the right tools. In this case can you view the CSV file that you will be reading from by opening it in Notepad so you know that it is intact? Do you know how to open/create a file? Do you know the various variable types available to you in C++? Do you know about the various options available forreading into strings using getline()? If the file you are reading has numerical fields and you wish to do calculations using the numerical values do you know how to convert strings into numerical values? Do you know how to write native types (and user defined types if needed) to the screen (which will basically be the same way you write them to file)?

If you know all of that, then you can write the program without any major problems. If not, learn a given concept in a smaller program first and then try to use that experience to do what is needed with that concept in your program.

First of all, thanks for helping me out...
I have studied c++ for almost one year.I know the basics...But i have never dealt with the file handling part. Can u please give me an example for opening an csv file and entering each element into an array. My program needs to handle only integer values, and that of one column in an Excel file.
I searched almost everywhere i could, but the examples i got was showing a lot of errors..

We don't do 'code to order' feel free to post your code and we'll help you work through your problems.

Or ask a much more specific question like 'How do I open a file'? if you can't find it on google (or equivalent)

Without knowing more about your skill set and specifics about what you are trying to, and in the spirit of not doing everythnig for you, I suspect I might end up with something looking like this as the guts of the prototcol used for reading of the file:

while(getline(fin, a[i++], ','));

Now I'd suggest using the reference material you have available/acculated over the last year to figure out what that line is doing and the importance of each part of it. (Feel free to point out it's weaknesses, too, so you can improve upon it!)

To use it. or something like it, in a program you will need to declare the individual parameters/variables used and initialize/associate them with appropriate values before you can get the line to work. Posting appropriate portions of your own code and asking for help when you get stuck like Murtan said is an excellent learning opportunity.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.