Welcome to the most active Linux Forum on the web.
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, 12: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, 02: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, 03:18 PM   #3
LQ Guru
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1190Reputation: 1190Reputation: 1190Reputation: 1190Reputation: 1190Reputation: 1190Reputation: 1190Reputation: 1190Reputation: 1190
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 03: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 6 09-13-2017 12:18 PM
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 > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:48 PM.

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