Ask your own question, for FREE!
Computer Science 7 Online
OpenStudy (davidusa):

How to make a Caesar C program? More like, how to use isupper(), islower(), and how to translate the plaintext into ciphertext?

OpenStudy (davidusa):

@e.mccormick

OpenStudy (e.mccormick):

Well, you knw the basis of the Ceasar cyper, shifting text, right?

OpenStudy (davidusa):

Not really- I know what functions to use, but I don't know how to use them :C But I know the loops, how to use them, and the normal C stuff like the header files, brackets, etc.

OpenStudy (davidusa):

I can show you what I've got so far. Do you want me to show you?

OpenStudy (e.mccormick):

I do not mean the computer part, I mean the Ceasar part.

OpenStudy (davidusa):

OHHHH!!!! Yeah I know it. Lol I was so confused when you said shifting text XD

OpenStudy (davidusa):

You're an awesome mod. :) Thanks for helping me! :D

OpenStudy (davidusa):

I hope you hit 2015 fans C:

OpenStudy (davidusa):

By the way it is Caesar not Ceasar lol I get it mixed up too

OpenStudy (e.mccormick):

I do not care about the Latin spelling. I have enough trouble with English. =P OK. So, the isupper and islower stuff just return if a character is upper case or if it is lower case. They return true or false.

OpenStudy (davidusa):

:P

OpenStudy (e.mccormick):

Typically, what you would use the upper/lower for in a C-Cypher is to see what range of characters you need to shift.

OpenStudy (davidusa):

Ok so here is my problem with those. I know what they do, but I don't really know how to use them correctly. I'm using the command line argument thing - my first line of real programming is int main(int words, string letters[]) So I keep getting argc and argv confused. How do I like... call... on the xth letter of the yth command line argument?

OpenStudy (e.mccormick):

A-Z is 65 to 90 a-z is 97 to 122 You need to find out if a letter is a capitol or lower case so you know if you need to shift it around in the 65 to 90 range or in the 97 to 122 range.

OpenStudy (davidusa):

Yea i know that stuff... But not much other than that =P

OpenStudy (e.mccormick):

The command line stuff makes an array.

OpenStudy (davidusa):

http://www.asciitable.com/ Right now I'm thinking of using the isupper/islower functions like this: if isupper is true asciivalue-65+key above thing+65, convert to char same way with islower, but then -97

OpenStudy (e.mccormick):

Just remember to pass it through a modulo. That will wrap it around if you pass z.

OpenStudy (davidusa):

Oh yea ok I got that. Thanks :)

OpenStudy (e.mccormick):

How comand line arguments work: http://www.tutorialspoint.com/cprogramming/c_command_line_arguments.htm

OpenStudy (davidusa):

Currently Uploading a video to show you my program.

OpenStudy (davidusa):

http://screencast-o-matic.com/watch/coeuc0eNl3 here. Please mute idk what got recorded :

OpenStudy (davidusa):

A helpful link I'm using :) Maybe you can use it to help others! https://reference.cs50.net/

OpenStudy (e.mccormick):

See, the problem with int main(int words, string letters[]) is that it is not really accurate. The main uses that for the command line arguments. The int is the number of arguments and will always be at least 1. The string or character array is the list of whitespace separated list of the arguments. The 0th position, or 1 aregument, that always exists is the name of the program. The 1st position is the first argument, and so on.

OpenStudy (davidusa):

well im doing this for a course, and im pretty sure i have to use int main(int words, string letters[])

OpenStudy (davidusa):

http://cdn.cs50.net/2015/x/psets/2/pset2/pset2.html#hail_caesar Here my eyes hurt :C

OpenStudy (e.mccormick):

Well, if they want it called that, fine. It makes little sense... but oh well.

OpenStudy (davidusa):

lol

OpenStudy (e.mccormick):

So where exactly are you having a problem?

OpenStudy (davidusa):

A few things. how to summon a certain letter of a word of a command line argument, and how to summon a certian word of a command line argument.

OpenStudy (davidusa):

and how to use the isupper function correctly. do i put it in an if function statement, or do i use it as its own function

OpenStudy (e.mccormick):

The string array hold the program name then any other arguments. So each one of those is a string. Getting the character out of a command line generated string is no different than from any other string.

OpenStudy (davidusa):

When I use int main(int words, string letters[]) How do I get the i'th word of the command line argument? I'm pretty sure it has some square brackets [] but i don't know which one to use and where everyting goes i too stupid

OpenStudy (e.mccormick):

letters[0] = the name of the program letters[1] = the first argument after the name of the program letters[2] = the second argument after the name of the program etc.

OpenStudy (davidusa):

That's exactly what I needed... What about the letters inside ?

OpenStudy (e.mccormick):

Are you sure these are C strings? Looks like C++...

OpenStudy (davidusa):

100 percent sure its C.

OpenStudy (e.mccormick):

Then how are you able to use the string class?

OpenStudy (davidusa):

Idk

OpenStudy (e.mccormick):

int main(int words, string letters[]) <--- that right there is a C++ string.

OpenStudy (davidusa):

Well I didn't know that. but I'm certain that this is C.

OpenStudy (e.mccormick):

They are probably loading a library. Know about 2 dimensional arrays?

OpenStudy (davidusa):

Yea

OpenStudy (e.mccormick):

Well, yo have a string array of strings and each string is an array of characters. So try things like: letters[1][0]

OpenStudy (davidusa):

Where do i write this

OpenStudy (e.mccormick):

Well, if you look at that, it sould be the first character of the first commmand line argument.

OpenStudy (davidusa):

Sorry I'm lost..

OpenStudy (e.mccormick):

A string is an array of characters. The command line arguments are an array of strings. In a 2d array, the first [ ] references the position within the outer array and the second [ ] is the position in the inner array. So, liest say my array is this: string words = {"One", "Two", "Three"} Then, the following is true: words[0] is One words[1] is Two words[2] is Three But what if I want to get into one character? Well, then I need to use the 2d aspects: words[0][0] is O words[0][1] is n words[0][2] is e

OpenStudy (davidusa):

oh okz i gets it

OpenStudy (e.mccormick):

Alo

OpenStudy (davidusa):

that was a long break xD where u go?

OpenStudy (e.mccormick):

Nowhere.

OpenStudy (davidusa):

why u dont respond lol

OpenStudy (e.mccormick):

"oh okz i gets it" That seemed like you were fine. I saw nothing else to respond to. Also, moderators tend to sit wherever they were last while they deal with reports, etc.

OpenStudy (davidusa):

Oh ok lol sorry I meant I understood what u said but i still dont know

OpenStudy (e.mccormick):

What do you not know?

OpenStudy (davidusa):

how to summon a letter im pretty sure its something simple like the words thing...

OpenStudy (davidusa):

The math chat's time is messed up.

OpenStudy (davidusa):

1 message is sent at 9 16, then another one after it is 9:12, then a 9 13,

OpenStudy (e.mccormick):

That was it. What you said you understood was it. How I got the O out of One that was part of One Two Three.

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!