N0 V0w3ls

Learning Goals

  • Practice using strings
  • Practice using 命令行参数s
  • 编写一个程序 entirely from scratch

leetspeak

背景

If you’ve been on the 互联网, you might have seen “leetspeak” (or “l33tsp36k” for our purposes!), which involves the 替换 of symbols for alphabetical characters, where those symbols somewhat resemble their alphabetical counterparts. In this 实验, you’ll 编写一个 program to replace certain vowels with digits!

Up until now, you’ve frequently written programs for which you’ve been provided 分发代码. You’ll notice when downloading the “distro” for this problem, you start with nothing 更多 than a couple of commonly used libraries and an empty main function. In this problem, you will convert a word, which you will input at the 命令行, to a corresponding word with numbers replacing vowels.

  • 提示
    • Do请注意, main function in the 分发代码 uses argc and argv. 请务必 use these!
    • 请务必 check 的 correct number of 命令行参数s before doing anything else in your main function.

演示

no-vowelsGif

入门

  1. Log into cs50.dev using your GitHub account.
  2. Click inside the terminal window and execute cd.
  3. At the $ prompt, type mkdir no-vowels
  4. Now execute cd no-vowels
  5. Then copy and paste wget https://cdn.cs50.net/2022/fall/实验s/2/no-vowels.c into your terminal to 下载 this 实验’s 分发代码.

实现细节

  • Implement your program in 名为 no-vowels.c in a directory called no-vowels.
  • 你的程序必须 accept a single 命令行参数, which will be the word that you want to convert.
  • If your program is executed without any 命令行参数s or with 更多 than one 命令行参数, your program should print an error message of your choice (with printf) and return from main a value of 1 (which tends to signify an error) immediately.
  • 你的程序必须 contain a function called replace which takes a string input and returns a string output.
  • This function will change the following vowels to numbers: a becomes 6, e becomes 3, i becomes 1, o becomes 0 and u does not change.
  • The input parameter 的 replace function will be argv[1] and the return value is the converted word.
  • The main function will then print the converted word, followed by \n.
  • You可能想要 to try using the switch statement in your replace function.

Thought 问题

Why might you want to use 命令行参数s rather than get_string, get_int, etc?

如何测试 Your Code

你的程序应该 behave per the例子below.

no-vowels/ $ ./no-vowels
Usage: ./no-vowels word
no-vowels/ $ ./no-vowels hello
h3ll0
no-vowels/ $ ./no-vowels pseudocode
ps3ud0c0d3

You can check your code using check50, a program that CS50 will use to test your code when you 提交, by typing in the following at the $ prompt. But be sure to test it自己 as well!

check50 cs50/实验s/2023/x/no-vowels

Green smilies 意思 your program has passed a test! Red frownies will indicate your program output something unexpected. Visit the URL that check50 outputs to see the input check50 handed to your program, what output it expected, and what output your program actually gave.

To evaluate that the style of your code (indentations and spacing) is correct, type in the following at the $ prompt.

style50 no-vowels.c

如何提交

No need to 提交! This is an 可选 练习题 completed with your 实验.