• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 17:38
CEST 23:38
KST 06:38
  • Home
  • Forum
  • Calendar
  • Streams
  • Liquipedia
  • Features
  • Store
  • EPT
  • TL+
  • StarCraft 2
  • Brood War
  • Smash
  • Heroes
  • Counter-Strike
  • Overwatch
  • Liquibet
  • Fantasy StarCraft
  • TLPD
  • StarCraft 2
  • Brood War
  • Blogs
Forum Sidebar
Events/Features
News
Featured News
[ASL19] Finals Recap: Standing Tall9HomeStory Cup 27 - Info & Preview18Classic wins Code S Season 2 (2025)16Code S RO4 & Finals Preview: herO, Rogue, Classic, GuMiho0TL Team Map Contest #5: Presented by Monster Energy6
Community News
[BSL20] Non-Korean Championship 4x BSL + 4x China1Flash Announces Hiatus From ASL63Weekly Cups (June 23-29): Reynor in world title form?13FEL Cracov 2025 (July 27) - $8000 live event22Esports World Cup 2025 - Final Player Roster16
StarCraft 2
General
Program: SC2 / XSplit / OBS Scene Switcher The SCII GOAT: A statistical Evaluation Statistics for vetoed/disliked maps Weekly Cups (June 23-29): Reynor in world title form? PiG Sty Festival #5: Playoffs Preview + Groups Recap
Tourneys
RSL: Revival, a new crowdfunded tournament series FEL Cracov 2025 (July 27) - $8000 live event Sparkling Tuna Cup - Weekly Open Tournament WardiTV Mondays Korean Starcraft League Week 77
Strategy
How did i lose this ZvP, whats the proper response Simple Questions Simple Answers
Custom Maps
[UMS] Zillion Zerglings
External Content
Mutation # 481 Fear and Lava Mutation # 480 Moths to the Flame Mutation # 479 Worn Out Welcome Mutation # 478 Instant Karma
Brood War
General
SC uni coach streams logging into betting site Player “Jedi” cheat on CSL Flash Announces Hiatus From ASL BW General Discussion Practice Partners (Official)
Tourneys
[BSL20] Non-Korean Championship 4x BSL + 4x China CSL Xiamen International Invitational The Casual Games of the Week Thread [BSL20] Grand Finals - Sunday 20:00 CET
Strategy
Simple Questions, Simple Answers I am doing this better than progamers do.
Other Games
General Games
Path of Exile Stormgate/Frost Giant Megathread Nintendo Switch Thread What do you want from future RTS games? Beyond All Reason
Dota 2
Official 'what is Dota anymore' discussion
League of Legends
Heroes of the Storm
Simple Questions, Simple Answers Heroes of the Storm 2.0
Hearthstone
Heroes of StarCraft mini-set
TL Mafia
TL Mafia Community Thread Vanilla Mini Mafia
Community
General
US Politics Mega-thread Russo-Ukrainian War Thread Summer Games Done Quick 2025! Trading/Investing Thread Things Aren’t Peaceful in Palestine
Fan Clubs
SKT1 Classic Fan Club! Maru Fan Club
Media & Entertainment
Anime Discussion Thread [Manga] One Piece [\m/] Heavy Metal Thread
Sports
2024 - 2025 Football Thread Formula 1 Discussion NBA General Discussion TeamLiquid Health and Fitness Initiative For 2023 NHL Playoffs 2024
World Cup 2022
Tech Support
Computer Build, Upgrade & Buying Resource Thread
TL Community
Blogs
Culture Clash in Video Games…
TrAiDoS
from making sc maps to makin…
Husyelt
Blog #2
tankgirl
StarCraft improvement
iopq
Trip to the Zoo
micronesia
Customize Sidebar...

Website Feedback

Closed Threads



Active: 610 users

C++ noob question

Blogs > eMbrace
Post a Reply
1 2 Next All
eMbrace
Profile Blog Joined January 2009
United States1300 Posts
Last Edited: 2009-10-17 02:49:29
October 17 2009 02:48 GMT
#1
I've been doing quite well in my class, but I've finally hit something that I can't figure out.

Basically, we have to decode a text file back to english (Caesar Cipher), and we have to run the text file through the our progame via the Command Prompt.

I've finished writing my code, but I can't get it to feed me back any output -- wrong or right.

I don't get an error or anything just this:

(checking to see if files I need are there, they are)
+ Show Spoiler +
[image loading]


(running the txt file through my program, maybe?)
+ Show Spoiler +
[image loading]


As you can see, nothing happens, and no errors appear either.

thats how I was instructed to do it and it's worked once before the other day, but now I finished writing my code and I can't test it =/

If you feel like taking the time, you can look at that as well:

+ Show Spoiler +
#include <iostream>
#include <iomanip>
#include <math.h>



using namespace std;


char reverseCaesar( char ch );
char convPunct( char ch );
char convDigit( char ch );
char convRest(char ch);
//***************************************************************************************************************************
int main()
{
char ch;
int change;


cin >> ch;

while ( cin )
{
char change;
if( isalpha(ch) )
{
change = reverseCaesar(ch);

}
else if (ispunct(ch) )
{
change = convPunct(ch);

}
else if (isdigit(ch) )
{
change = convDigit(ch);

}

else
change = convRest(ch);

cin >> ch;
}


system ("pause");
return 0;
}

//***************************************************************************************************************************

char reverseCaesar( char ch )
{
int i;

if (ch <= 47 && ch > 44)
{
i = (int)ch + 23;
}
else if (ch <=99 && ch > 96)
{
i = (int)ch +23;
}
else

i = (int)ch - 3;

return char(i);
}

char convPunct( char ch )
{
switch(ch)
{
case ',': return '0';
break;
case '.': return '1';
break;
case '$': return '2';
break;
case '&': return '3';
break;
case '%': return '4';
break;
case '*': return '5';
break;
case '(': return '6';
break;
case ')': return '7';
break;
case '?': return '8';
break;
case '!': return '9';

default: return ch;

}
}

char convDigit( char ch )
{
switch(ch)
{
case '0': return '!';
break;
case '1': return ',';
break;
case '2': return ')';
break;
case '3': return '(';
break;
case '4': return '?';
break;
case '5': return '-';
break;
case '6': return '&';
break;
case '7': return '$';
break;
case '8': return '.';
break;
case '9': return '+';
break;

default: return ch;

}
}

char convRest(char ch)
{
if(ch==21)
ch='\n';
else if(ch==22)
ch=' ';
else
ch=ch;

return ch;
}


I haven't added documentation, but it's fairly straight forward -- taking the characters from the txt file and decoding them (we had to write and use our own functions as well).

I'm willing to bet my program wouldn't work even if I could see it, but i'd at least like to try.

any help would appreciated, it's due in a couple of hours =)

if I have to i'll just submit and see if I can edit and resubmit tomorrow .

thanks.







*
Shade692003
Profile Joined August 2005
Canada702 Posts
October 17 2009 02:58 GMT
#2
been pretty long since I've done anything like coding or w/e, but if I understand correctly you enter your text file path as a parameter for your program? shouldn't there be parameters in your main then?
I hate the post below mine because it feels War3-ish.
DrTJEckleburg
Profile Blog Joined February 2009
United States1080 Posts
October 17 2009 02:58 GMT
#3
I have no help for your question, but I do believe that your reign at the top of LB will end after you bet on MBC over KT Rolster.
Im pretty good at whistling with my hands, especially when Im holding a whistle.
paper
Profile Blog Joined September 2004
13196 Posts
Last Edited: 2009-10-17 02:59:19
October 17 2009 02:59 GMT
#4
[image loading]


voting for MBC is your problem


edit: YOU GUYS ARE TOO FAST
Hates Fun🤔
keV.
Profile Blog Joined February 2009
United States3214 Posts
Last Edited: 2009-10-17 03:04:04
October 17 2009 03:00 GMT
#5
Wait a minute something isn't right here.


I'm pretty sure you can't read a txt file with cin, while expecting a char.

I don't know the details of your assignment, but do you take the file you are reading from as a parameter? If you do, then you definitely need to take some command line arguments. If not, then you can just open the file in your main or accept it by input string, and read char by char until the end of file.
"brevity is the soul of wit" - William Shakesman
AcrossFiveJulys
Profile Blog Joined September 2005
United States3612 Posts
Last Edited: 2009-10-17 03:05:10
October 17 2009 03:01 GMT
#6
I'm a little confused about what you're asking, but I think you are asking why your program doesn't "do" anything when you run it. Okay, so given that...

Your second screenshot shows you running the program with the file as input correctly.

Now, your program doesn't produce any output on the command prompt because you aren't telling it to print anything. Use cout if you want to print messages to the command prompt. If you are trying to create a new file that contains the translation of the original file, you'll need to use an ofstream and output to that, or use "> some_file" when running the program and print to some_file using cout.

eMbrace
Profile Blog Joined January 2009
United States1300 Posts
October 17 2009 03:01 GMT
#7
On October 17 2009 11:58 DrTJEckleburg wrote:
I have no help for your question, but I do believe that your reign at the top of LB will end after you bet on MBC over KT Rolster.


i'm on top for a reason
AcrossFiveJulys
Profile Blog Joined September 2005
United States3612 Posts
October 17 2009 03:03 GMT
#8
On October 17 2009 12:00 keV. wrote:
Wait a minute something isn't right here.


I'm pretty sure you can't read a txt file with cin, while expecting a char.


Yes you can. Since he's using the "<" operator when running the program, it changes the stdin stream (which is what cin uses) to refer to the file instead of user input.
Shade692003
Profile Joined August 2005
Canada702 Posts
October 17 2009 03:03 GMT
#9
On October 17 2009 12:00 keV. wrote:
Wait a minute something isn't right here.


I'm pretty sure you can't read a txt file with cin, while expecting a char.



I think the cin are for reading the characters in the text files, once they are read he changes them according to their values. could be wrong tho.

Anyhow there is no output like the other guy said
I hate the post below mine because it feels War3-ish.
eMbrace
Profile Blog Joined January 2009
United States1300 Posts
October 17 2009 03:05 GMT
#10
On October 17 2009 12:01 AcrossFiveJulys wrote:
I'm a little confused about what you're asking, but I think you are asking why your program doesn't "do" anything when you run it. Okay, so given that...

Your second screenshot shows you running the program with the file as input correctly.

Now, your program doesn't produce any output on the command prompt because you aren't telling it to print anything. Use cout if you want to print messages to the command prompt. If you are trying to create a new file that contains the translation of the original file, you'll need to use an ofstream and output to that.



to put it into a new file, they taught us this format

program < input.txt > new.txt

i get a new file with nothing in it =/
Shade692003
Profile Joined August 2005
Canada702 Posts
Last Edited: 2009-10-17 03:06:46
October 17 2009 03:05 GMT
#11
So hmm, shoudn't you cout that ''change'' variable?

Edit: Try to cout the change variable at the end of the while loop, might cout the value into the new text file.
I hate the post below mine because it feels War3-ish.
keV.
Profile Blog Joined February 2009
United States3214 Posts
Last Edited: 2009-10-17 03:06:53
October 17 2009 03:05 GMT
#12
On October 17 2009 12:03 AcrossFiveJulys wrote:
Show nested quote +
On October 17 2009 12:00 keV. wrote:
Wait a minute something isn't right here.


I'm pretty sure you can't read a txt file with cin, while expecting a char.


Yes you can. Since he's using the "<" operator when running the program, it changes the stdin stream (which is what cin uses) to refer to the file instead of user input.


I don't think reading from a file without a file handle is a good idea.

its sad how long its been since I've worked with simple I/O input...
"brevity is the soul of wit" - William Shakesman
vAltyR
Profile Blog Joined July 2008
United States581 Posts
Last Edited: 2009-10-17 03:08:40
October 17 2009 03:05 GMT
#13
Commenting is your best friend. Especially when you're asking others to help with your program. I didn't think it'd make that much difference, but I've had time where I look back on code and think "wtf was I doing here again?"

Do you need to separate it into functions like that? Sometimes it gets confusing debugging so many functions, especially when the code isn't your own.


EDIT: Wait a second... You're reading this from a file, right? You have nothing set up for file IO.
내 호버크라프트는 장어로 가득 차 있어요
Ironson
Profile Joined February 2008
20 Posts
October 17 2009 03:06 GMT
#14
The program is well formed, but it doesn't output anything! You need to write the output to "cout" and stream it into a file. Your command would become something like: pgm6 < input.txt > output.txt
keV.
Profile Blog Joined February 2009
United States3214 Posts
October 17 2009 03:07 GMT
#15
Like whats been said in this thread, you need to either rewrite the original file as you read char by char or you need to print the output to a a new file or screen.
"brevity is the soul of wit" - William Shakesman
eMbrace
Profile Blog Joined January 2009
United States1300 Posts
Last Edited: 2009-10-17 03:09:14
October 17 2009 03:08 GMT
#16
On October 17 2009 12:06 Ironson wrote:
The program is well formed, but it doesn't output anything! You need to write the output to "cout" and stream it into a file. Your command would become something like: pgm6 < input.txt > output.txt


ok right, but how exactly do I make my program cout all the decoded characters at once after the loop is over?

and sorry for the code with out comments -- we did have to write functions to use in the main, i guess it's a way of them making us learn how they work.



Ironson
Profile Joined February 2008
20 Posts
October 17 2009 03:09 GMT
#17
Before your second "cin >> ch;", place "cout << change;".
eMbrace
Profile Blog Joined January 2009
United States1300 Posts
Last Edited: 2009-10-17 03:14:24
October 17 2009 03:13 GMT
#18
On October 17 2009 12:09 Ironson wrote:
Before your second "cin >> ch;", place "cout << change;".



woah, it worked.

got all the decoded next in a new file.

thanks a lot everyone -- you may have saved my A in this class.

now I can watch MBC just roll over KT tonight
keV.
Profile Blog Joined February 2009
United States3214 Posts
October 17 2009 03:13 GMT
#19
this should give you simple error checking output.

+ Show Spoiler +

int main()
{
char ch;
int change;


cin >> ch;

while ( cin )
{
char change;
if( isalpha(ch) )
{
change = reverseCaesar(ch);


}
else if (ispunct(ch) )
{
change = convPunct(ch);


}
else if (isdigit(ch) )
{
change = convDigit(ch);


}

else
change = convRest(ch);
//output goes here

cin >> ch;
}


system ("pause");
return 0;
}

"brevity is the soul of wit" - William Shakesman
eMbrace
Profile Blog Joined January 2009
United States1300 Posts
October 17 2009 03:17 GMT
#20
On October 17 2009 12:13 keV. wrote:
this should give you simple error checking output.

+ Show Spoiler +

int main()
{
char ch;
int change;


cin >> ch;

while ( cin )
{
char change;
if( isalpha(ch) )
{
change = reverseCaesar(ch);


}
else if (ispunct(ch) )
{
change = convPunct(ch);


}
else if (isdigit(ch) )
{
change = convDigit(ch);


}

else
change = convRest(ch);
//output goes here

cin >> ch;
}


system ("pause");
return 0;
}



thanks a bunch kev
1 2 Next All
Please log in or register to reply.
Live Events Refresh
BSL: ProLeague
18:00
Grand Finals - bo9
Dewalt vs Bonyth
ZZZero.O601
LiquipediaDiscussion
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
Livibee 74
ProTech73
StarCraft: Brood War
ZZZero.O 601
Terrorterran 25
League of Legends
Grubby4772
Dendi1480
Counter-Strike
fl0m1918
Super Smash Bros
Mew2King211
Chillindude70
Westballz45
Heroes of the Storm
Khaldor837
Liquid`Hasu676
Other Games
summit1g4866
FrodaN2854
Mlord689
mouzStarbuck417
tarik_tv263
Pyrionflax228
ViBE124
elazer108
Organizations
Other Games
gamesdonequick44472
EGCTV1715
BasetradeTV43
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 18 non-featured ]
StarCraft 2
• musti20045 63
• Adnapsc2 20
• Kozan
• Migwel
• AfreecaTV YouTube
• sooper7s
• intothetv
• IndyKCrew
• LaughNgamezSOOP
StarCraft: Brood War
• 3DClanTV 101
• blackmanpl 3
• STPLYoutube
• ZZZeroYoutube
• BSLYoutube
Dota 2
• Ler140
League of Legends
• masondota2714
Other Games
• imaqtpie2305
• Shiphtur386
Upcoming Events
Wardi Open
13h 23m
Replay Cast
1d 2h
Sparkling Tuna Cup
1d 12h
WardiTV European League
1d 18h
MaNa vs sebesdes
Mixu vs Fjant
ByuN vs HeRoMaRinE
ShoWTimE vs goblin
Gerald vs Babymarine
Krystianer vs YoungYakov
PiGosaur Monday
2 days
The PondCast
2 days
WardiTV European League
2 days
Jumy vs NightPhoenix
Percival vs Nicoract
ArT vs HiGhDrA
MaxPax vs Harstem
Scarlett vs Shameless
SKillous vs uThermal
Replay Cast
3 days
RSL Revival
3 days
ByuN vs SHIN
Clem vs Reynor
Replay Cast
4 days
[ Show More ]
RSL Revival
4 days
Classic vs Cure
FEL
4 days
RSL Revival
5 days
FEL
5 days
FEL
5 days
Sparkling Tuna Cup
6 days
RSL Revival
6 days
FEL
6 days
Liquipedia Results

Completed

BSL 2v2 Season 3
HSC XXVII
Heroes 10 EU

Ongoing

JPL Season 2
BSL Season 20
Acropolis #3
KCM Race Survival 2025 Season 2
CSL 17: 2025 SUMMER
Copa Latinoamericana 4
Jiahua Invitational
Championship of Russia 2025
RSL Revival: Season 1
Murky Cup #2
BLAST.tv Austin Major 2025
ESL Impact League Season 7
IEM Dallas 2025
PGL Astana 2025
Asian Champions League '25
BLAST Rivals Spring 2025
MESA Nomadic Masters
CCT Season 2 Global Finals
IEM Melbourne 2025

Upcoming

2025 ACS Season 2: Qualifier
CSLPRO Last Chance 2025
CSL Xiamen Invitational
2025 ACS Season 2
CSLPRO Chat StarLAN 3
K-Championship
uThermal 2v2 Main Event
SEL Season 2 Championship
FEL Cracov 2025
Esports World Cup 2025
StarSeries Fall 2025
FISSURE Playground #2
BLAST Open Fall 2025
BLAST Open Fall Qual
Esports World Cup 2025
BLAST Bounty Fall 2025
BLAST Bounty Fall Qual
IEM Cologne 2025
FISSURE Playground #1
TLPD

1. ByuN
2. TY
3. Dark
4. Solar
5. Stats
6. Nerchio
7. sOs
8. soO
9. INnoVation
10. Elazer
1. Rain
2. Flash
3. EffOrt
4. Last
5. Bisu
6. Soulkey
7. Mini
8. Sharp
Sidebar Settings...

Advertising | Privacy Policy | Terms Of Use | Contact Us

Original banner artwork: Jim Warren
The contents of this webpage are copyright © 2025 TLnet. All Rights Reserved.