GolfHos
 
*
April 24, 2024, 08:47:27 AM
Username: Password: Duration:

c++ gurus? - read in arbitrary csv...

 
Pages: [1]   Go Down
  Print  
Author Topic: c++ gurus? - read in arbitrary csv...  (Read 2404 times)
0 Members and 1 Lurker/Spider are viewing this topic.
Aske
Lederhosen

Karma: 120
Posts: 31405
Offline Offline


View ProfileIgnore this user
c++ gurus? - read in arbitrary csv...
« on: April 26, 2007, 07:23:37 PM »

I used to be ok with c++ ... I'm still moderately ok (just browsed an old book)...

i remember strongly how to work with arrays, ints, do math, write function calls , etc

i remember diddly squat about how to work with strings (hence, how to adequately treat the stream that fget or  fscanf  takes in, etc) ....

so...

ANYONE have handy a good generic  csv reader that will take arbitrary csv file and read it into an array on the fly, each whitespace or comma (and obviously line ends) creating new array elements? 

I am sure I can write it ... but I'd rather save debugging time...
Logged Return to Top

Quote
Russia has invaded a sovereign neighboring state and threatens a democratic government elected by its people. Such an action is unacceptable in the 21st century.
--  Chimpy McFlightsuit, CEO of Bu$hco Industries of 'Merka
Uisce Beatha
Amazing Technicolor Dreamcoat
From: In the Jar

Karma: 116
Posts: 7357
Offline Offline

Get me the tank!

View ProfileIgnore this user
Re: c++ gurus? - read in arbitrary csv...
« Reply #1 on: April 26, 2007, 07:35:05 PM »

It's been a million years and the last time I had C++ code laying around it was probably on a 286. 

But... strings are just arrays of characters.  If you're comfortable with arrays just str.copy(buf, i) and go crazy. 

But you'll have to debug.   Devil

Man, that was ages ago.  I'm old.

edit:  If you're gonna break on whitespace it's technically not CSV, yes?   Devil
« Last Edit: April 26, 2007, 07:40:02 PM by Uisce Beatha » Logged Return to Top

"If you're darker than a caramel, Reverend Al speaks for you." - Aasif Mandvi
"Well, you can tell by the way I use my walk, I'm a woman's man: no time to talk." - stroh
Aske
Lederhosen

Karma: 120
Posts: 31405
Offline Offline


View ProfileIgnore this user
Re: c++ gurus? - read in arbitrary csv...
« Reply #2 on: April 26, 2007, 07:41:31 PM »

It's been a million years and the last time I had C++ code laying around it was probably on a 286. 

But... strings are just arrays of characters.  If you're comfortable with arrays just str.copy(buf, i) and go crazy. 

But you'll have to debug.   Devil

Man, that was ages ago.  I'm old.

edit:  If you're gonna break on whitespace it's technically not CSV, yes?   Devil


per your edit note... i was thinking about if the 'cell' is empty...   
Logged Return to Top

Quote
Russia has invaded a sovereign neighboring state and threatens a democratic government elected by its people. Such an action is unacceptable in the 21st century.
--  Chimpy McFlightsuit, CEO of Bu$hco Industries of 'Merka
E-A-G-L-E!
Rich Corinthian Leather Jacket
From: The Land of 10,000+ Slushy Ice Rinks

Karma: 23
Posts: 5095
Offline Offline


View Profile WWWIgnore this user
Re: c++ gurus? - read in arbitrary csv...
« Reply #3 on: April 26, 2007, 07:45:09 PM »

I was only *just* starting to learn c++ a year or so ago, then had to drop it 'cause of lack of time.  Sad
Logged Return to Top

He is no fool who gives what he cannot keep to gain that which he cannot lose.  - Jim Elliot

gleek
Flak Jacket

Karma: 107
Posts: 9510
Offline Offline

E chu ta!

View ProfileIgnore this user
Re: c++ gurus? - read in arbitrary csv...
« Reply #4 on: April 26, 2007, 07:47:25 PM »

http://www.linuxquestions...s/showthread.php?t=126337

Code:
#include <iostream>
#include <fstream>
#include <strstream>

using namespace std;

int main()
{
char buffer1[2048];
char buffer2[2048];
istrstream ostr1(buffer1, 2048);
istrstream ostr2(buffer2, 2048);
int values1[100];
int values2[100];
int c=0;

ifstream fin("data.txt");

fin.getline(buffer1, 2048);
fin.getline(buffer2, 2048);

while (ostr1 >> values1[c])
{
ostr2 >> values2[c++];
}

for (int i=0;i<c;i++)
{
cout << values1[i] << ":" << values2[i] << endl;
}

return 0;
}
Logged Return to Top

Woman, open the door, don't let it sting. I wanna breathe that fire again.
Aske
Lederhosen

Karma: 120
Posts: 31405
Offline Offline


View ProfileIgnore this user
Re: c++ gurus? - read in arbitrary csv...
« Reply #5 on: April 26, 2007, 07:49:31 PM »

http://www.linuxquestions...s/showthread.php?t=126337

Code:
#include <iostream>
#include <fstream>
#include <strstream>

using namespace std;

int main()
{
char buffer1[2048];
char buffer2[2048];
istrstream ostr1(buffer1, 2048);
istrstream ostr2(buffer2, 2048);
int values1[100];
int values2[100];
int c=0;

ifstream fin("data.txt");

fin.getline(buffer1, 2048);
fin.getline(buffer2, 2048);

while (ostr1 >> values1[c])
{
ostr2 >> values2[c++];
}

for (int i=0;i<c;i++)
{
cout << values1[i] << ":" << values2[i] << endl;
}

return 0;
}


thanks, I will give it a try.
 Cheers
Logged Return to Top

Quote
Russia has invaded a sovereign neighboring state and threatens a democratic government elected by its people. Such an action is unacceptable in the 21st century.
--  Chimpy McFlightsuit, CEO of Bu$hco Industries of 'Merka
gleek
Flak Jacket

Karma: 107
Posts: 9510
Offline Offline

E chu ta!

View ProfileIgnore this user
Re: c++ gurus? - read in arbitrary csv...
« Reply #6 on: April 26, 2007, 07:51:18 PM »

I don't want a large farva.
Logged Return to Top

Woman, open the door, don't let it sting. I wanna breathe that fire again.
Aske
Lederhosen

Karma: 120
Posts: 31405
Offline Offline


View ProfileIgnore this user
Re: c++ gurus? - read in arbitrary csv...
« Reply #7 on: April 26, 2007, 07:57:41 PM »

I don't want a large farva.

Shenanigans.
Logged Return to Top

Quote
Russia has invaded a sovereign neighboring state and threatens a democratic government elected by its people. Such an action is unacceptable in the 21st century.
--  Chimpy McFlightsuit, CEO of Bu$hco Industries of 'Merka
Salamander
Vest & Plus Fours
From: Blerghland

Karma: 18
Posts: 772
Offline Offline

värsta bergatroll

View ProfileIgnore this user
Re: c++ gurus? - read in arbitrary csv...
« Reply #8 on: April 27, 2007, 08:50:02 AM »

I'll have to pistol whip you now.
Logged Return to Top


Magnus Frater te spectat
Pages: [1]   Return to Top
  Print  
 
Jump to:  

Related Posts
linux(ubuntu) gurus?
n00b. ;) ;D
by Torpedo

photography/digital camera gurus?
LMAO!
by stroh

photography/digital camera gurus?
[sm_shock] nice  [sm_thumbsup2]
by dystopia

photography/digital camera gurus?
I hate you.Love,Jules, E-A-G-L-E!, and Torp
by gleek

 


 
  Powered by SMF | SMF © 2001-2009, Lewis Media

Dilber MC Theme by HarzeM