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

Jus*_*ble 1 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;
}
Run Code Online (Sandbox Code Playgroud)

当我在Netbeans中运行它时,我得到以下内容:

RUN FAILED (exit value 1, total time: 98ms)
Run Code Online (Sandbox Code Playgroud)

如果我删除该行

printf(process_string[i]);
Run Code Online (Sandbox Code Playgroud)

程序运行但没有任何打印到控制台(显然).

我在这里缺少什么想法?

Ed *_*eal 9

你需要一行格式

printf(process_string[i]);
Run Code Online (Sandbox Code Playgroud)

printf("%c", process_string[i]);
Run Code Online (Sandbox Code Playgroud)

  • 是的,我对实际编译的发布代码感到惊讶.但也许发布的代码也不正确. (2认同)