微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

程序在第 37 行显示错误,我试图显示一个字符,但它说它是一个整数因此,它不显示第 37 行并跳过它

如何解决程序在第 37 行显示错误,我试图显示一个字符,但它说它是一个整数因此,它不显示第 37 行并跳过它

/* > 显示错误:main.c:37:23: 警告:格式‘%s’需要‘char *’类型的参数,但参数 2 的类型为‘int’[-Wformat=] printf("名称是:%s\n",s[x].n[20]); */

        #include<stdio.h>
            struct student
            {
                int roll;
                char n[20];
                float per;
            }`enter code here`
            main()
            {
                int n;
                printf("Enter number of students");
                scanf("%d",&n);
                struct student s[n];
                for(int i=1;i<=n;i++)
                {
                printf("Roll number:\n");
                scanf("%d",&s[i].roll);
                printf("Name:\n");
                scanf("%s",&s[i].n[20]);
                printf("Percentage:\n");
                scanf("%f",&s[i].per);
                }
              int x;
              printf("Student you want to acess:\n");
              scanf("%d",&x);
               if(x<=n){
                printf("The information of the stuent is as follows:\n");
                printf("Roll no is: %d\n",s[x].roll);
                printf("Name is: %s\n",s[x].n[20]);     //does not print idk why
                printf("Percentage is: %f\n",s[x].per);
               }
               else if(x>n)
               {
               printf("Error:Input no valid!");
               }
            }

解决方法

printf("Name is: %s\n",s[x].n[20]); 正在尝试将 char 处的 s[x].n[20] 打印为 字符串,该 s[x].n 位于该数组之外。

要将 printf("Name is: %s\n",s[x].n); 打印为字符串,请使用 import Vue from 'vue' import VueI18n from 'vue-i18n' Vue.use(VueI18n) function loadLocaleMessages() { const locales = require.context('./locales',true,/[A-Za-z0-9-_,\s]+\.json$/i) const messages = {} locales.keys().forEach(key => { const matched = key.match(/([A-Za-z0-9-_]+)\./i) if (matched && matched.length > 1) { const locale = matched[1] messages[locale] = locales(key) } }) return messages } export const selected_locale = navigator.language.split('-')[0] export default new VueI18n({ locale: selected_locale || process.env.VUE_APP_I18N_LOCALE || 'en',fallbackLocale: process.env.VUE_APP_I18N_FALLBACK_LOCALE || 'en',messages: loadLocaleMessages() })

提示:启用所有编译器警告以节省时间。

代码中也存在其他问题。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。