小编Joh*_*ohn的帖子

在分隔符处分割一行文本后打印

我在打印时遇到问题.当我请求用户插入int它工作时,但是当试图将其切换到char输入时它变得棘手并且不会打印任何东西.

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

int main() {
    const char delim[2] = ",";
    char *token;
    int j = 0;
    char *hh;
    FILE *ptr_file;
    char buf[1000];

    ptr_file = fopen("input.txt", "r");
    if (!ptr_file)
        return 1;

    char *pt[] = { "H", "He", "Li", "Be", "B", "C", "N", "O", "F", "Ne", "Na" };

    printf("what element do you want(Use atomic number)");
    scanf("%s", &hh);

    for (j = 0; j <= 3; j++) {
        if (hh == pt[j]) {
            fgets(buf, 1000, …
Run Code Online (Sandbox Code Playgroud)

c pointers scanf

2
推荐指数
1
解决办法
43
查看次数

标签 统计

c ×1

pointers ×1

scanf ×1