| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1122 人关注过本帖
标题:我的这段代码错在何处,求教大神!
只看楼主 加入收藏
xxcyy
Rank: 1
等 级:新手上路
帖 子:23
专家分:0
注 册:2016-8-12
结帖率:66.67%
收藏
已结贴  问题点数:15 回复次数:3 
我的这段代码错在何处,求教大神!
#include <stdio.h>
#define NAMESIZE 30

struct data{
    float amount;
    char fname[NAMESIZE];
    char lname[NAMESIZE];
} rec;

int main(void)
{
    printf("Enter the donor's first and last names,\n");
    printf("separated by a space:");
    scanf_s("%s %s", &rec.fname, &rec.lname);

    printf("Enter the donation amount:");
    scanf_s("%f", &rec.amount);

    printf("\nDonor %s %s gave $%.2f.\n", rec.fname, rec.lname, rec.amount);

    return 0;
}

[此贴子已经被作者于2016-9-7 17:26编辑过]

搜索更多相关主题的帖子: include return amount Enter color 
2016-09-07 09:48
grmmylbs
Rank: 14Rank: 14Rank: 14Rank: 14
等 级:贵宾
威 望:54
帖 子:1409
专家分:5845
注 册:2016-2-14
收藏
得分:0 
scanf_s需要有长度参数

程序代码:
#include <stdio.h>
#define NAMESIZE 30

struct data {
    float amount;
    char fname[NAMESIZE];
    char lname[NAMESIZE];
} rec;

int main(void)
{
    printf("Enter the donor's first and last names,\n");
    printf("separated by a space:");
    scanf_s("%s%s", rec.fname, NAMESIZE, rec.lname, NAMESIZE);

    printf("Enter the donation amount:");
    scanf_s("%f", &rec.amount);

    printf("\nDonor %s %s gave %.2f.\n", rec.fname, rec.lname, rec.amount);

    return 0;
}
2016-09-07 10:02
xxcyy
Rank: 1
等 级:新手上路
帖 子:23
专家分:0
注 册:2016-8-12
收藏
得分:0 
回复 2楼 grmmylbs
你太棒了!解决了我的问题。非常感谢。
2016-09-07 17:26
海贼王杰克
Rank: 1
等 级:新手上路
帖 子:2
专家分:8
注 册:2016-9-7
收藏
得分:8 
回复 3楼 xxcyy
就是scanf-s这个格式不对吧.
2016-09-09 19:32
快速回复:我的这段代码错在何处,求教大神!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.015375 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved