arrays - 在 C 中打印 *string_variable 缺少什么
问题描述
我正在做一个项目,需要用破折号替换字符串中的字母。我什至无法让字符串打印更少的替换字符。我认为问题在于我对指针缺乏理解(我尚未涵盖)。
我试过迭代,复制到另一个变量和 %s 但没有一个工作......我错过了什么?
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(void) {
printf("Welcome to the Computer Science Themed Hangman Game!\n The words the you will be asked to guess in this game will be related to computer science.\n");
char words[15][20] = {"motherboard", "keyboard", "bytes", "programmer", "array", "processor", "loop", "algorithm", "intelligence", "boolean", "compute", "debug", "output", "function", "memory"};
int i, mistakes = 0;
int random_word_index = rand() % 15; //selects a random number from 0 to 15
int word_length = strlen(words[random_word_index]);
printf("%d\n", word_length);
char *selected_word = words[random_word_index];
char word[20];
strcpy(word, selected_word);
printf("%s", word);
char *current_status;
printf("%s", current_status);
for (i=0; i<word_length; ++i){
current_status[i] = '_';
}
printf("%s", current_status);
解决方案
推荐阅读
- amazon-s3 - 使用 cloudfront 从私有 S3 文件夹下载文件
- google-chrome-extension - 在 chrome 扩展中出现错误:与 http://*******.com/ 上的跨站点资源关联的 cookie 设置为没有“SameSite”属性
- android - 我是否需要先请求一个真正的广告才能从 logcat 中获取设备 ID,以便我可以添加一个测试设备?
- artifactory - Jfrog C++ 安装柯南包
- sql - 永远不会满足包含 Select 的函数的约束
- c++ - 避免 C++ 中重复的子类定义
- c - C Segmentation Fault 将 scanf 用于 2D 数组时
- java - 给定带有通配符的 AWS 操作或 AWS 服务,是否有 Java API 可以列出所有操作?
- excel - 在 COUNTIF 和 COUNTIFS 中需要 EXCEL
- flutter - Flutter - 处理程序!= null 不正确