sprintf...Again

Printing something only after it is done being converted

Page 1 of 1

2 Replies - 527 Views - Last Post: 21 April 2009 - 11:35 PM Rate Topic: -----

#1 IngeniousHax  Icon User is offline

  • |>|20-514<|{3|2

Reputation: 79
  • View blog
  • Posts: 1,366
  • Joined: 28-March 09

sprintf...Again

Posted 21 April 2009 - 11:26 PM

I am currently trying to print a string only after it is converted tolower, and right now the output looks something like this:
OUTPUT:
Please enter your full name and birthdate: First Last B-day
Example: JohnDoe2201989...No spaces please.
HARRY
================
hARRY
haRRY
harRY
harrY
harry
___________________________________________________
Here is the code.
#include <iostream>
#include <fstream>
#include <string>
using namespace std;

int main(int argc, char *argv[])
{
string Name;
int i, c, b, a;
char buf[5096];
char d, e, f;

cout << "Please enter your full name and birthdate: First Last B-day" << endl;
cout << "Example: JohnDoe2201989...No spaces please." << endl; 
cin >> Name;
cout << "================" << endl;
for(i = 0; i < Name.length(); i++)
 {
   Name[i] = tolower(Name[i]);
	cout << Name << endl;
   }//close name.length
}//close main


I realise I have way more variables than I need, but I always start with more than I need, and when I don't use them I just delete them. and I may end up using fstream later on as a modification to the program...
Basically what it's supposed to do is take in a user-defined string, and than take that string and give each character a numerical value from 1-26, depending on the letter it is, using [ ( c - 'a' ) + 1 ] <-----gives an numeric value from 1-26 of the alphabet....
I'm supposed to use recursion, but I don't really comprehend that yet, I have to read up on it, but for now, I just want to get sprintf down.

This post has been edited by IngeniousHax: 21 April 2009 - 11:27 PM


Is This A Good Question/Topic? 0
  • +

Replies To: sprintf...Again

#2 OliveOyl3471  Icon User is offline

  • Everybody's crazy but me!
  • member icon

Reputation: 134
  • View blog
  • Posts: 6,581
  • Joined: 11-July 07

Re: sprintf...Again

Posted 21 April 2009 - 11:31 PM

View PostIngeniousHax, on 22 Apr, 2009 - 01:26 AM, said:

I am currently trying to print a string only after it is converted tolower


Move this cout << Name << endl; outside of the for loop
for(i = 0; i < Name.length(); i++)
 {
   Name[i] = tolower(Name[i]);
	
   }//close name.length
cout << Name << endl;


(I kinda like the way you have it output in increments though. lol)

This post has been edited by OliveOyl3471: 21 April 2009 - 11:33 PM

Was This Post Helpful? 1
  • +
  • -

#3 IngeniousHax  Icon User is offline

  • |>|20-514<|{3|2

Reputation: 79
  • View blog
  • Posts: 1,366
  • Joined: 28-March 09

Re: sprintf...Again

Posted 21 April 2009 - 11:35 PM

Haha, Thanks for the reply, I really appreciate it.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1