加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

为什么我的c prog在打印出一个数组时停止工作

发布时间:2020-12-16 10:33:57 所属栏目:百科 来源:网络整理
导读:在这个程序中,我正在使用fgets解析csv文件,并根据我对c prog的了解,将文件转换为数组. 因此,当我用printf(“%s”,输入)打印出来时,我得到10,20,30,但是当我包含printf(“%s”,输入[0])时,程序停止工作. 这是我正在进行的计划: #include stdio.h#include s
在这个程序中,我正在使用fgets解析csv文件,并根据我对c prog的了解,将文件转换为数组.

因此,当我用printf(“%s”,输入)打印出来时,我得到10,20,30,但是当我包含printf(“%s”,输入[0])时,程序停止工作.
这是我正在进行的计划:

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

struct xa 
{
  int x;
  int y;
  int z;
} xo;

int main()
{
    FILE *dudufile;
    char filename[]="dodo.dat";
    char input[1679];
    dudufile=fopen(filename,"r");

    while ( fgets(input,1679,dudufile ) != NULL )
    {
        printf("%sn",input);
        printf("%sn",input[0]);
        struct xa;
        xo.y=input[1];
        printf("%d",xo.y);      
    }

    return 0;
}

解决方法

编译警告:

warning: format ‘%s’ expects argument of type ‘char *’,
but argument 2 has type ‘int’ [-Wformat]

应该:

printf("%cn",input[0]);

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读