c - 在C中打印字符串中的所有字符

标签 c

我有一个非常简单的程序来打印字符串中的字符,但由于某种原因它不起作用:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

void * print_chars(char *process_string) {
    int i;
    int string_len;

    string_len = strlen(process_string);

    printf("String is %s, and its length is %d", process_string, string_len);

    for(i = 0; i < string_len; i++) {
        printf(process_string[i]);
    }

    printf("\n");
}

int main(void) {
    char *process_string;

    process_string = "This is the parent process.";

    print_chars(process_string);

    return 0;
}

当我在 Netbeans 中运行它时,我得到以下信息:

RUN FAILED (exit value 1, total time: 98ms)

如果我删除行

printf(process_string[i]);

程序运行但没有任何内容输出到控制台(很明显)。

知道我在这里遗漏了什么吗?

最佳答案

行中需要格式

printf(process_string[i]);

printf("%c", process_string[i]);

关于c - 在C中打印字符串中的所有字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13457616/

相关文章:

c - 安装 sysfs 时 mount() 失败

c - 具有不同参数的函数

C++ Sys/Stat.h 有错误?

c - 如何在C中首先迭代头为 `NULL`的循环链表?

c - 使用 GCC 生成 a.out 文件格式

c - 为什么编译器同时询问加入的日、月、年?

python - 在Python中调用C函数并返回2个值

c - "too large"对象是否具有自动存储持续时间未定义的行为?

c - Facebook 采访 : Implement readline function

C fcntl 抽象函数不起作用