LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 02-08-2010, 12:40 PM   #1
gregarion
Member
 
Registered: Jan 2010
Posts: 69

Rep: Reputation: 15
Output display in c++


Hey guys, i am having problem with displaying my text. my text file is displayed in such a way and is called test.......
Code:
Sam Worthington ... Jake SullyasZoe Saldana ... NeytiriasSigourney Weaver ... Dr. Grace AugustineasStephen Lang ... Colonel Miles QuaritchasJoel Moore ... Norm Spellman (as Joel David Moore)asGiovanni Ribisi ... Parker SelfridgeasMichelle Rodriguez ... Trudy ChaconasLaz Alonso ... Tsu'teyasWes Studi ... EytukanasCCH Pounder ... MoatasDileep Rao ... Dr. Max PatelasMatt Gerald ... Corporal Lyle WainfleetasSean Anthony Moran ... Private FikeasJason Whyte ... Cryo Vault Med TechasScott Lawrence ... Venture Star Crew Chiefmore
What i am trying to do is for the program to read "as" and then from there start a new line... thus the expected output is...


Code:
Sam Worthington ... Jake Sully
Zoe Saldana ... Neytiri
Sigourney Weaver ... Dr. Grace Augustine
Stephen Lang ... Colonel Miles Quaritch
Joel Moore ... Norm Spellman (as Joel David Moore)
.........(and so on)



This is my coding..



Code:
string templine ;
string line;
ifstream myfile ("test");


while (getline (myfile,templine) )
line.append(templine);

char str [] = line ;
char delims[] = " ";
char *result = NULL;
result = strtok( str, delims );
while( result != NULL ) {
printf( result );
result = strtok( NULL, delims );
}


I keep getting the error saying ...

Code:
editmain.cpp.98:error: initializer fails to determine size of 'str'

what does this mean, and how can i be able to format my file in the way i want?
 
Old 02-08-2010, 02:29 PM   #2
David1357
Senior Member
 
Registered: Aug 2007
Location: South Carolina, U.S.A.
Distribution: Ubuntu, Fedora Core, Red Hat, SUSE, Gentoo, DSL, coLinux, uClinux
Posts: 1,302
Blog Entries: 1

Rep: Reputation: 107Reputation: 107
Quote:
Originally Posted by gregarion View Post
Code:
editmain.cpp.98:error: initializer fails to determine size of 'str'
There are not 98 lines of code in the sample you provided.

To solve the problem mentioned in the error, look at the place where "str" is initialized.
 
Old 02-08-2010, 03:18 PM   #3
johnsfine
Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,094

Rep: Reputation: 1111Reputation: 1111Reputation: 1111Reputation: 1111Reputation: 1111Reputation: 1111Reputation: 1111Reputation: 1111Reputation: 1111
I can guess which line is 98
Code:
char str [] = line ;
But I can't guess what you hope to accomplish with that line. You seem to be asking the compiler at compile time to know the run time contents of a string.

Probably you want
Code:
char* str = line.c_str() ;
But I'm far from sure of that. If you use c_str that way, be aware that is not copying the contents of the string, just pointing to them. So str will be valid only as long as line doesn't get modified. That seems to fit the way you use str in strtok, but you haven't shown enough code for me to be sure you don't modify line before you are done with str.

Last edited by johnsfine; 02-08-2010 at 03:22 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Anyone display console output to screensaver? TheDirtyScreech Linux - Software 3 08-17-2007 08:19 AM
Output display address problem in GAS surfer41 Programming 3 10-26-2006 08:46 PM
RCA Output as Primary Display? basketkase999 Linux - Hardware 2 12-01-2005 01:23 PM
display ifconfig output in php ?? ALInux Programming 1 10-29-2005 04:23 PM
TV-Out display different output than Monitor with Nvidia MasterC Linux - Hardware 1 08-13-2003 06:13 PM


All times are GMT -5. The time now is 05:46 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration