新闻资讯

质量为本、客户为根、勇于拼搏、务实创新

< 返回新闻资讯列表

c语言输出字符串的有什么方法,c语言输出字符的ASCII码程序

发布时间:2024-06-03 16:31:10

c语言输出字符串的有甚么方法

  1. 使用printf函数输出字符串:
#include <stdio.h>

int main() {
    char str[] = "Hello, World!";
    printf("%s
", str);
    return 0;
}
  1. 使用puts函数输出字符串:
#include <stdio.h>

int main() {
    char str[] = "Hello, World!";
    puts(str);
    return 0;
}
  1. 使用fputs函数输出字符串到指定文件流:
#include <stdio.h>

int main() {
    char str[] = "Hello, World!";
    FILE *file = fopen("output.txt", "w");
    fputs(str, file);
    fclose(file);
    return 0;
}
  1. 使用putchar函数逐字符输出字符串:
#include <stdio.h>

int main() {
    char str[] = "Hello, World!";
    int i = 0;
    while (str[i] != '') {
        putchar(str[i]);
        i++;
    }
    putchar('
');
    return 0;
}