scanf函数的两个字符串和浮点数。 [英] Scanf for a two strings and a float number.

查看:527
本文介绍了scanf函数的两个字符串和浮点数。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建需要采取从用户的三个输入的菜单。

I am creating a menu that needs to take in an three inputs from the users.

    char *fullname;
    char *date;
    float sal;
    printf("\nEnter full name: ");

line92

line92

scanf("%s", &fullname);

printf("\nEnter hire date: ");

94号线

scanf("%s", &date);

printf("\nEnter salary: ");

96号线

scanf("%d", &sal);

这是我recieving误差

These are the error I am recieving

    Employee.c:92: warning: format ‘%s’ expects type ‘char *’, but argument 2 has type ‘char **’
    Employee.c:94: warning: format ‘%s’ expects type ‘char *’, but argument 2 has type ‘char **’
    Employee.c:96: warning: format ‘%d’ expects type ‘int *’, but argument 2 has type ‘float *’

我能得到什么原因造成这些问题的解释?

Can I get an explanation of what is causing these issues?

推荐答案

有几个问题:

首先:

当您使用 scanf函数字符串你不使用&安培; 。因此,只要 scanf函数(%S,全名);

When you use scanf for strings you do not use the &. So just scanf("%s", fullname);.

二:

您的指针不会被初始化。试试这个:

Your pointers aren't initialized. Try this instead:

char fullname[256];
char date[256];

这将工作,只要你最多255个字符的输入。

This will work as long as you input at most 255 characters.

第三:

您最后键入 scanf函数不匹配。你传递在格式字符串中的浮动时已经指定你一个 INT 。试试这个:

Your typing for the last scanf doesn't match. You're passing in a float when you've specified an int in the format string. Try this:

scanf("%f", &sal);

这篇关于scanf函数的两个字符串和浮点数。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆