Visit the LQ Articles and Editorials section
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 02-08-2010, 01:40 PM   #1
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.......
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...

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..

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

while (getline (myfile,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 ...

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, 03:29 PM   #2
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
Originally Posted by gregarion View Post
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, 04:18 PM   #3
LQ Guru
Registered: Dec 2007
Distribution: Centos
Posts: 5,277

Rep: Reputation: 1174Reputation: 1174Reputation: 1174Reputation: 1174Reputation: 1174Reputation: 1174Reputation: 1174Reputation: 1174Reputation: 1174
I can guess which line is 98
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
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 04:22 PM.


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 09:19 AM
Output display address problem in GAS surfer41 Programming 3 10-26-2006 09:46 PM
RCA Output as Primary Display? basketkase999 Linux - Hardware 2 12-01-2005 02:23 PM
display ifconfig output in php ?? ALInux Programming 1 10-29-2005 05:23 PM
TV-Out display different output than Monitor with Nvidia MasterC Linux - Hardware 1 08-13-2003 07:13 PM

All times are GMT -5. The time now is 08:00 AM.

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