问题描述
/* > 显示错误: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()
})
。
提示:启用所有编译器警告以节省时间。
代码中也存在其他问题。