Attempting to output contents of a text file

  • (3 Pages)
  • +
  • 1
  • 2
  • 3

37 Replies - 779 Views - Last Post: 02 April 2013 - 10:01 AM Rate Topic: -----

#16 jimblumberg  Icon User is online

  • member icon


Reputation: 4101
  • View blog
  • Posts: 12,700
  • Joined: 25-December 09

Re: Attempting to output contents of a text file

Posted 02 April 2013 - 07:24 AM

Then you need to convert your text file and abbreviation file to either upper or lower case. You can use toupper() or tolower() to do this for each character of each string to be converted.

Jim
Was This Post Helpful? 0
  • +
  • -

#17 mrbondysa  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 02-April 13

Re: Attempting to output contents of a text file

Posted 02 April 2013 - 07:31 AM

Could you possibly give me some sample code please
Was This Post Helpful? 0
  • +
  • -

#18 jimblumberg  Icon User is online

  • member icon


Reputation: 4101
  • View blog
  • Posts: 12,700
  • Joined: 25-December 09

Re: Attempting to output contents of a text file

Posted 02 April 2013 - 07:34 AM

What have you tried? Did you look up the documentation for toupper() or tolower()?

Jim
Was This Post Helpful? 0
  • +
  • -

#19 mrbondysa  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 02-April 13

Re: Attempting to output contents of a text file

Posted 02 April 2013 - 07:52 AM

I had already checked documentation on tolower I'm just completely confused at how to implement it into my code
Was This Post Helpful? 0
  • +
  • -

#20 jimblumberg  Icon User is online

  • member icon


Reputation: 4101
  • View blog
  • Posts: 12,700
  • Joined: 25-December 09

Re: Attempting to output contents of a text file

Posted 02 April 2013 - 08:11 AM

You need to show what you've tried and then ask specific questions since I have no idea what has you so confused.

Jim
Was This Post Helpful? 0
  • +
  • -

#21 mrbondysa  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 02-April 13

Re: Attempting to output contents of a text file

Posted 02 April 2013 - 08:21 AM

I looked at the documentation you provided and am unsure how to make this:char str[]="Test String.\n";
appropriate to my code
Was This Post Helpful? 0
  • +
  • -

#22 jimblumberg  Icon User is online

  • member icon


Reputation: 4101
  • View blog
  • Posts: 12,700
  • Joined: 25-December 09

Re: Attempting to output contents of a text file

Posted 02 April 2013 - 08:25 AM

You would use one of your strings. What string do you want to change the case?

Jim
Was This Post Helpful? 0
  • +
  • -

#23 mrbondysa  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 02-April 13

Re: Attempting to output contents of a text file

Posted 02 April 2013 - 08:27 AM

Wouldn't I have to do it for both of them, because each text file would have to match exactly right to show up as an abbreviation properly
Was This Post Helpful? 0
  • +
  • -

#24 jimblumberg  Icon User is online

  • member icon


Reputation: 4101
  • View blog
  • Posts: 12,700
  • Joined: 25-December 09

Re: Attempting to output contents of a text file

Posted 02 April 2013 - 08:34 AM

Since you abbreviations seem to be in a mixed case, yes.

Jim
Was This Post Helpful? 0
  • +
  • -

#25 mrbondysa  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 02-April 13

Re: Attempting to output contents of a text file

Posted 02 April 2013 - 08:37 AM

string newString;
	vector<std::string> textFileVector;
	vector<std::string> abbrevVector;


which one would it be, newString or the vectors ?
Was This Post Helpful? 0
  • +
  • -

#26 jimblumberg  Icon User is online

  • member icon


Reputation: 4101
  • View blog
  • Posts: 12,700
  • Joined: 25-December 09

Re: Attempting to output contents of a text file

Posted 02 April 2013 - 08:51 AM

That's up to you. You can convert the string to the proper case before you insert it into the vector or you can iterate thru the vectors and change the values after you have populated the vectors.

Jim
Was This Post Helpful? 0
  • +
  • -

#27 mrbondysa  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 02-April 13

Re: Attempting to output contents of a text file

Posted 02 April 2013 - 08:54 AM

With newString it just comes up with the error 3 IntelliSense: initialization with '{...}' expected for aggregate object
Was This Post Helpful? 0
  • +
  • -

#28 jimblumberg  Icon User is online

  • member icon


Reputation: 4101
  • View blog
  • Posts: 12,700
  • Joined: 25-December 09

Re: Attempting to output contents of a text file

Posted 02 April 2013 - 08:57 AM

Show the code that produced these errors.

Jim
Was This Post Helpful? 0
  • +
  • -

#29 mrbondysa  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 02-April 13

Re: Attempting to output contents of a text file

Posted 02 April 2013 - 09:02 AM

	while (!textfile.eof(), str[k])
	{
		char str[] = newString;
		c=str[k];
		putchar (tolower(c));
		k++;
		textfile >> newString;
		textFileVector.push_back(newString);
		cout << newString << " ";


here
Was This Post Helpful? 0
  • +
  • -

#30 jimblumberg  Icon User is online

  • member icon


Reputation: 4101
  • View blog
  • Posts: 12,700
  • Joined: 25-December 09

Re: Attempting to output contents of a text file

Posted 02 April 2013 - 09:13 AM

Why are you playing with character arrays and putchar()? You already have a string and you don't want to print this string to the console.

You need to convert each character of your string to the proper case. You can't do this until after you read the string from the file.

while (textfile >> newString) // read the character from the file.
{
   // loop thru newString and convert each character to the proper case.

// Once you convert the case you can continue.
	textFileVector.push_back(newString);
	cout << newString << " ";


Do you understand how to access the individual characters of a string?

Jim

This post has been edited by jimblumberg: 02 April 2013 - 09:14 AM

Was This Post Helpful? 0
  • +
  • -

  • (3 Pages)
  • +
  • 1
  • 2
  • 3