| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1416 人关注过本帖
标题:求本程序正解,以及为什么
只看楼主 加入收藏
jj19971130
Rank: 2
等 级:论坛游民
帖 子:35
专家分:69
注 册:2011-11-30
结帖率:100%
收藏
已结贴  问题点数:10 回复次数:11 
求本程序正解,以及为什么
程序代码:
#include<stdio.h>
int main()
{
    extern char Name[52];
    int Number[52];
    float Grade[52];
    int index;
    for(index=0;index<=51;index++)
    {
        printf("No.%d's grade is:\n",Number[index+1]);
        scanf("%f",Grade[index]);
    }
    printf("Number   Name    Grade");
    for(index=0;index<=51;index++)
    {
        printf("%d        %c    %f",Number[index+1],Name[index+1],Grade[index]);
    }
    return 0;
}
这是第一个文件,
程序代码:
#include<stdio.h>
Name[1]="a";
Name[2]="s";
Name[3]="d";
Name[4]="Z";
Name[5]="f";
Name[6]="g";
Name[7]="X";
Name[8]="C";
Name[9]="V";
Name[10]="h";
Name[11]="j";
Name[12]="k";
Name[13]="l";
Name[14]=";";
Name[15]="'";
Name[16]="z";
Name[17]="x";
Name[18]="c";
Name[19]="v";
Name[20]="b";
Name[21]="n";
Name[22]="m";
Name[23]=",";
Name[24]=".";
Name[25]="/";
Name[26]="q";
Name[27]="w";
Name[28]="e";
Name[29]="r";
Name[30]="t";
Name[31]="y";
Name[32]="u";
Name[33]="i";
Name[34]="o";
Name[35]="p";
Name[36]="[";
Name[37]="]";
Name[38]="\";
Name[39]="`";
Name[40]="A";
Name[41]="S";
Name[42]="D";
Name[43]="F";
Name[44]="G";
Name[45]="H";
Name[46]="J";
Name[47]="K";
Name[48]="L";
Name[49]="Q";
Name[50]="W";
Name[51]="E";
这是第二个。
问题是:E:\visual c++ 6.0\text2.cpp(2) : error C2501: 'Name' : missing storage-class or type specifiers
E:\visual c++ 6.0\text2.cpp(2) : error C2440: 'initializing' : cannot convert from 'char [2]' to 'int [1]'
        There is no context in which this conversion is possible
E:\visual c++ 6.0\text2.cpp(3) : error C2501: 'Name' : missing storage-class or type specifiers
E:\visual c++ 6.0\text2.cpp(3) : error C2369: 'Name' : redefinition; different subscripts
        E:\visual c++ 6.0\text2.cpp(2) : see declaration of 'Name'
E:\visual c++ 6.0\text2.cpp(3) : error C2440: 'initializing' : cannot convert from 'char [2]' to 'int [2]'
        There is no context in which this conversion is possible
E:\visual c++ 6.0\text2.cpp(4) : error C2501: 'Name' : missing storage-class or type specifiers
E:\visual c++ 6.0\text2.cpp(4) : error C2369: 'Name' : redefinition; different subscripts
        E:\visual c++ 6.0\text2.cpp(2) : see declaration of 'Name'
E:\visual c++ 6.0\text2.cpp(4) : error C2440: 'initializing' : cannot convert from 'char [2]' to 'int [3]'
        There is no context in which this conversion is possible
E:\visual c++ 6.0\text2.cpp(5) : error C2501: 'Name' : missing storage-class or type specifiers
E:\visual c++ 6.0\text2.cpp(5) : error C2369: 'Name' : redefinition; different subscripts
        E:\visual c++ 6.0\text2.cpp(2) : see declaration of 'Name'
E:\visual c++ 6.0\text2.cpp(5) : error C2440: 'initializing' : cannot convert from 'char [2]' to 'int [4]'
        There is no context in which this conversion is possible
E:\visual c++ 6.0\text2.cpp(6) : error C2501: 'Name' : missing storage-class or type specifiers
E:\visual c++ 6.0\text2.cpp(6) : error C2369: 'Name' : redefinition; different subscripts
        E:\visual c++ 6.0\text2.cpp(2) : see declaration of 'Name'
E:\visual c++ 6.0\text2.cpp(6) : error C2440: 'initializing' : cannot convert from 'char [2]' to 'int [5]'
        There is no context in which this conversion is possible
E:\visual c++ 6.0\text2.cpp(7) : error C2501: 'Name' : missing storage-class or type specifiers
E:\visual c++ 6.0\text2.cpp(7) : error C2369: 'Name' : redefinition; different subscripts
        E:\visual c++ 6.0\text2.cpp(2) : see declaration of 'Name'
E:\visual c++ 6.0\text2.cpp(7) : error C2440: 'initializing' : cannot convert from 'char [2]' to 'int [6]'
        There is no context in which this conversion is possible
E:\visual c++ 6.0\text2.cpp(8) : error C2501: 'Name' : missing storage-class or type specifiers
E:\visual c++ 6.0\text2.cpp(8) : error C2369: 'Name' : redefinition; different subscripts
        E:\visual c++ 6.0\text2.cpp(2) : see declaration of 'Name'
E:\visual c++ 6.0\text2.cpp(8) : error C2440: 'initializing' : cannot convert from 'char [2]' to 'int [7]'
        There is no context in which this conversion is possible
E:\visual c++ 6.0\text2.cpp(9) : error C2501: 'Name' : missing storage-class or type specifiers
E:\visual c++ 6.0\text2.cpp(9) : error C2369: 'Name' : redefinition; different subscripts
        E:\visual c++ 6.0\text2.cpp(2) : see declaration of 'Name'
E:\visual c++ 6.0\text2.cpp(9) : error C2440: 'initializing' : cannot convert from 'char [2]' to 'int [8]'
        There is no context in which this conversion is possible
E:\visual c++ 6.0\text2.cpp(10) : error C2501: 'Name' : missing storage-class or type specifiers
E:\visual c++ 6.0\text2.cpp(10) : error C2369: 'Name' : redefinition; different subscripts
        E:\visual c++ 6.0\text2.cpp(2) : see declaration of 'Name'
E:\visual c++ 6.0\text2.cpp(10) : error C2440: 'initializing' : cannot convert from 'char [2]' to 'int [9]'
        There is no context in which this conversion is possible
E:\visual c++ 6.0\text2.cpp(11) : error C2501: 'Name' : missing storage-class or type specifiers
E:\visual c++ 6.0\text2.cpp(11) : error C2369: 'Name' : redefinition; different subscripts
        E:\visual c++ 6.0\text2.cpp(2) : see declaration of 'Name'
E:\visual c++ 6.0\text2.cpp(11) : error C2440: 'initializing' : cannot convert from 'char [2]' to 'int [10]'
        There is no context in which this conversion is possible
E:\visual c++ 6.0\text2.cpp(12) : error C2501: 'Name' : missing storage-class or type specifiers
E:\visual c++ 6.0\text2.cpp(12) : error C2369: 'Name' : redefinition; different subscripts
        E:\visual c++ 6.0\text2.cpp(2) : see declaration of 'Name'
E:\visual c++ 6.0\text2.cpp(12) : error C2440: 'initializing' : cannot convert from 'char [2]' to 'int [11]'
        There is no context in which this conversion is possible
E:\visual c++ 6.0\text2.cpp(13) : error C2501: 'Name' : missing storage-class or type specifiers
E:\visual c++ 6.0\text2.cpp(13) : error C2369: 'Name' : redefinition; different subscripts
        E:\visual c++ 6.0\text2.cpp(2) : see declaration of 'Name'
E:\visual c++ 6.0\text2.cpp(13) : error C2440: 'initializing' : cannot convert from 'char [2]' to 'int [12]'
        There is no context in which this conversion is possible
E:\visual c++ 6.0\text2.cpp(14) : error C2501: 'Name' : missing storage-class or type specifiers
E:\visual c++ 6.0\text2.cpp(14) : error C2369: 'Name' : redefinition; different subscripts
        E:\visual c++ 6.0\text2.cpp(2) : see declaration of 'Name'
E:\visual c++ 6.0\text2.cpp(14) : error C2440: 'initializing' : cannot convert from 'char [2]' to 'int [13]'
        There is no context in which this conversion is possible
E:\visual c++ 6.0\text2.cpp(15) : error C2501: 'Name' : missing storage-class or type specifiers
E:\visual c++ 6.0\text2.cpp(15) : error C2369: 'Name' : redefinition; different subscripts
        E:\visual c++ 6.0\text2.cpp(2) : see declaration of 'Name'
E:\visual c++ 6.0\text2.cpp(15) : error C2440: 'initializing' : cannot convert from 'char [2]' to 'int [14]'
        There is no context in which this conversion is possible
E:\visual c++ 6.0\text2.cpp(16) : error C2501: 'Name' : missing storage-class or type specifiers
E:\visual c++ 6.0\text2.cpp(16) : error C2369: 'Name' : redefinition; different subscripts
        E:\visual c++ 6.0\text2.cpp(2) : see declaration of 'Name'
E:\visual c++ 6.0\text2.cpp(16) : error C2440: 'initializing' : cannot convert from 'char [2]' to 'int [15]'
        There is no context in which this conversion is possible
E:\visual c++ 6.0\text2.cpp(17) : error C2501: 'Name' : missing storage-class or type specifiers
E:\visual c++ 6.0\text2.cpp(17) : error C2369: 'Name' : redefinition; different subscripts
        E:\visual c++ 6.0\text2.cpp(2) : see declaration of 'Name'
E:\visual c++ 6.0\text2.cpp(17) : error C2440: 'initializing' : cannot convert from 'char [2]' to 'int [16]'
        There is no context in which this conversion is possible
E:\visual c++ 6.0\text2.cpp(18) : error C2501: 'Name' : missing storage-class or type specifiers
E:\visual c++ 6.0\text2.cpp(18) : error C2369: 'Name' : redefinition; different subscripts
        E:\visual c++ 6.0\text2.cpp(2) : see declaration of 'Name'
E:\visual c++ 6.0\text2.cpp(18) : error C2440: 'initializing' : cannot convert from 'char [2]' to 'int [17]'
        There is no context in which this conversion is possible
E:\visual c++ 6.0\text2.cpp(19) : error C2501: 'Name' : missing storage-class or type specifiers
E:\visual c++ 6.0\text2.cpp(19) : error C2369: 'Name' : redefinition; different subscripts
        E:\visual c++ 6.0\text2.cpp(2) : see declaration of 'Name'
E:\visual c++ 6.0\text2.cpp(19) : error C2440: 'initializing' : cannot convert from 'char [2]' to 'int [18]'
        There is no context in which this conversion is possible
E:\visual c++ 6.0\text2.cpp(20) : error C2501: 'Name' : missing storage-class or type specifiers
E:\visual c++ 6.0\text2.cpp(20) : error C2369: 'Name' : redefinition; different subscripts
        E:\visual c++ 6.0\text2.cpp(2) : see declaration of 'Name'
E:\visual c++ 6.0\text2.cpp(20) : error C2440: 'initializing' : cannot convert from 'char [2]' to 'int [19]'
        There is no context in which this conversion is possible
E:\visual c++ 6.0\text2.cpp(21) : error C2501: 'Name' : missing storage-class or type specifiers
E:\visual c++ 6.0\text2.cpp(21) : error C2369: 'Name' : redefinition; different subscripts
        E:\visual c++ 6.0\text2.cpp(2) : see declaration of 'Name'
E:\visual c++ 6.0\text2.cpp(21) : error C2440: 'initializing' : cannot convert from 'char [2]' to 'int [20]'
        There is no context in which this conversion is possible
E:\visual c++ 6.0\text2.cpp(22) : error C2501: 'Name' : missing storage-class or type specifiers
E:\visual c++ 6.0\text2.cpp(22) : error C2369: 'Name' : redefinition; different subscripts
        E:\visual c++ 6.0\text2.cpp(2) : see declaration of 'Name'
E:\visual c++ 6.0\text2.cpp(22) : error C2440: 'initializing' : cannot convert from 'char [2]' to 'int [21]'
        There is no context in which this conversion is possible
E:\visual c++ 6.0\text2.cpp(23) : error C2501: 'Name' : missing storage-class or type specifiers
E:\visual c++ 6.0\text2.cpp(23) : error C2369: 'Name' : redefinition; different subscripts
        E:\visual c++ 6.0\text2.cpp(2) : see declaration of 'Name'
E:\visual c++ 6.0\text2.cpp(23) : error C2440: 'initializing' : cannot convert from 'char [2]' to 'int [22]'
        There is no context in which this conversion is possible
E:\visual c++ 6.0\text2.cpp(24) : error C2501: 'Name' : missing storage-class or type specifiers
E:\visual c++ 6.0\text2.cpp(24) : error C2369: 'Name' : redefinition; different subscripts
        E:\visual c++ 6.0\text2.cpp(2) : see declaration of 'Name'
E:\visual c++ 6.0\text2.cpp(24) : error C2440: 'initializing' : cannot convert from 'char [2]' to 'int [23]'
        There is no context in which this conversion is possible
E:\visual c++ 6.0\text2.cpp(25) : error C2501: 'Name' : missing storage-class or type specifiers
E:\visual c++ 6.0\text2.cpp(25) : error C2369: 'Name' : redefinition; different subscripts
        E:\visual c++ 6.0\text2.cpp(2) : see declaration of 'Name'
E:\visual c++ 6.0\text2.cpp(25) : error C2440: 'initializing' : cannot convert from 'char [2]' to 'int [24]'
        There is no context in which this conversion is possible
E:\visual c++ 6.0\text2.cpp(26) : error C2501: 'Name' : missing storage-class or type specifiers
E:\visual c++ 6.0\text2.cpp(26) : error C2369: 'Name' : redefinition; different subscripts
        E:\visual c++ 6.0\text2.cpp(2) : see declaration of 'Name'
E:\visual c++ 6.0\text2.cpp(26) : error C2440: 'initializing' : cannot convert from 'char [2]' to 'int [25]'
        There is no context in which this conversion is possible
E:\visual c++ 6.0\text2.cpp(27) : error C2501: 'Name' : missing storage-class or type specifiers
E:\visual c++ 6.0\text2.cpp(27) : error C2369: 'Name' : redefinition; different subscripts
        E:\visual c++ 6.0\text2.cpp(2) : see declaration of 'Name'
E:\visual c++ 6.0\text2.cpp(27) : error C2440: 'initializing' : cannot convert from 'char [2]' to 'int [26]'
        There is no context in which this conversion is possible
E:\visual c++ 6.0\text2.cpp(28) : error C2501: 'Name' : missing storage-class or type specifiers
E:\visual c++ 6.0\text2.cpp(28) : error C2369: 'Name' : redefinition; different subscripts
        E:\visual c++ 6.0\text2.cpp(2) : see declaration of 'Name'
E:\visual c++ 6.0\text2.cpp(28) : error C2440: 'initializing' : cannot convert from 'char [2]' to 'int [27]'
        There is no context in which this conversion is possible
E:\visual c++ 6.0\text2.cpp(29) : error C2501: 'Name' : missing storage-class or type specifiers
E:\visual c++ 6.0\text2.cpp(29) : error C2369: 'Name' : redefinition; different subscripts
        E:\visual c++ 6.0\text2.cpp(2) : see declaration of 'Name'
E:\visual c++ 6.0\text2.cpp(29) : error C2440: 'initializing' : cannot convert from 'char [2]' to 'int [28]'
        There is no context in which this conversion is possible
E:\visual c++ 6.0\text2.cpp(30) : error C2501: 'Name' : missing storage-class or type specifiers
E:\visual c++ 6.0\text2.cpp(30) : error C2369: 'Name' : redefinition; different subscripts
        E:\visual c++ 6.0\text2.cpp(2) : see declaration of 'Name'
E:\visual c++ 6.0\text2.cpp(30) : error C2440: 'initializing' : cannot convert from 'char [2]' to 'int [29]'
        There is no context in which this conversion is possible
E:\visual c++ 6.0\text2.cpp(31) : error C2501: 'Name' : missing storage-class or type specifiers
E:\visual c++ 6.0\text2.cpp(31) : error C2369: 'Name' : redefinition; different subscripts
        E:\visual c++ 6.0\text2.cpp(2) : see declaration of 'Name'
E:\visual c++ 6.0\text2.cpp(31) : error C2440: 'initializing' : cannot convert from 'char [2]' to 'int [30]'
        There is no context in which this conversion is possible
E:\visual c++ 6.0\text2.cpp(32) : error C2501: 'Name' : missing storage-class or type specifiers
E:\visual c++ 6.0\text2.cpp(32) : error C2369: 'Name' : redefinition; different subscripts
        E:\visual c++ 6.0\text2.cpp(2) : see declaration of 'Name'
E:\visual c++ 6.0\text2.cpp(32) : error C2440: 'initializing' : cannot convert from 'char [2]' to 'int [31]'
        There is no context in which this conversion is possible
E:\visual c++ 6.0\text2.cpp(33) : error C2501: 'Name' : missing storage-class or type specifiers
E:\visual c++ 6.0\text2.cpp(33) : error C2369: 'Name' : redefinition; different subscripts
        E:\visual c++ 6.0\text2.cpp(2) : see declaration of 'Name'
E:\visual c++ 6.0\text2.cpp(33) : error C2440: 'initializing' : cannot convert from 'char [2]' to 'int [32]'
        There is no context in which this conversion is possible
E:\visual c++ 6.0\text2.cpp(34) : error C2501: 'Name' : missing storage-class or type specifiers
E:\visual c++ 6.0\text2.cpp(34) : error C2369: 'Name' : redefinition; different subscripts
        E:\visual c++ 6.0\text2.cpp(2) : see declaration of 'Name'
E:\visual c++ 6.0\text2.cpp(34) : error C2440: 'initializing' : cannot convert from 'char [2]' to 'int [33]'
        There is no context in which this conversion is possible
E:\visual c++ 6.0\text2.cpp(35) : error C2501: 'Name' : missing storage-class or type specifiers
E:\visual c++ 6.0\text2.cpp(35) : error C2369: 'Name' : redefinition; different subscripts
        E:\visual c++ 6.0\text2.cpp(2) : see declaration of 'Name'
E:\visual c++ 6.0\text2.cpp(35) : error C2440: 'initializing' : cannot convert from 'char [2]' to 'int [34]'
        error count exceeds 100; stopping compilation
执行 cl.exe 时出错.



这是怎么回事
搜索更多相关主题的帖子: index 
2011-12-04 17:33
jj19971130
Rank: 2
等 级:论坛游民
帖 子:35
专家分:69
注 册:2011-11-30
收藏
得分:0 
Name[]的赋值可举例,不必完全一样
2011-12-04 17:36
jj19971130
Rank: 2
等 级:论坛游民
帖 子:35
专家分:69
注 册:2011-11-30
收藏
得分:0 
我看书上是这样的,就照搬过来了
2011-12-04 17:57
jj19971130
Rank: 2
等 级:论坛游民
帖 子:35
专家分:69
注 册:2011-11-30
收藏
得分:0 
程序代码:
#include<stdio.h>
int main()
{
    char Name[]={"q","w","e","r","t","y","u","i","o","p","a","s","d","f","g","h","j","k","l","z","x","c","v","b","n","m","Q","W","E","R","T","Y","U","I","O","P","A","S","D","F","G","H","J","K","L","Z","X","C","V","B","N"};
    int Number[52];
    float Grade[52];
    int index;
    for(index=0;index<=51;index++)
    {
        printf("No.%d's grade is:\n",Number[index+1]);
        scanf("%f",Grade[index]);
    }
    printf("Number   Name    Grade");
    for(index=0;index<=51;index++)
    {
        printf("%d        %c    %f",Number[index+1],Name[index],Grade[index]);
    }
    return 0;
}
错误为:too many initializers。
这个又是怎么回事!!
2011-12-04 18:35
hellovfp
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:禁止访问
威 望:30
帖 子:2976
专家分:7697
注 册:2009-7-21
收藏
得分:6 
  char Name[]={'q','w','e','r','t','y','u','i','o','p','a','s','d','f','g','h','j','k','l','z','x','c','v','b','n','m','Q','W','E','R','T','Y','U','I','O','P','A','S','D','F','G','H','J','K','L','Z','X','C','V','B','N'};

我们都在路上。。。。。
2011-12-05 11:17
jj19971130
Rank: 2
等 级:论坛游民
帖 子:35
专家分:69
注 册:2011-11-30
收藏
得分:0 
感谢楼上
程序代码:
#include<stdio.h>
int main()
{
    char Name[]={'q','w','e','r','t','y','u','i','o','p','a','s','d','f','g','h','j','k','l','z','x','c','v','b','n','m','Q','W','E','R','T','Y','U','I','O','P','A','S','D','F','G','H','J','K','L','Z','X','C','V','B','N'};
    int Number[51]={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51};
    long double Grade[51];
    int index;
    for(index=0;index<=51;index++)
    {
        printf("No.%d's grade is:\n",Number[index]);
        scanf("%f",Grade[index]);
    }
    printf("Number   Name    Grade");
    for(index=0;index<=51;index++)
    {
        printf("%d\t%c\t%f\t",Number[index-1],Name[index],Grade[index]);
    }
    return 0;
}
但是这个又是神马问题
图片附件: 游客没有浏览图片的权限,请 登录注册
2011-12-05 18:43
strivelong87
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:68
专家分:159
注 册:2011-11-24
收藏
得分:0 
这个初始化看的我头疼
2011-12-05 19:12
宝宝7大人
Rank: 1
等 级:新手上路
帖 子:12
专家分:6
注 册:2011-10-11
收藏
得分:4 
for(index=0;index<=51;index++)
改成index<51
2011-12-05 19:21
jj19971130
Rank: 2
等 级:论坛游民
帖 子:35
专家分:69
注 册:2011-11-30
收藏
得分:0 
谢谢提醒
图片附件: 游客没有浏览图片的权限,请 登录注册
但还有问题
2011-12-05 19:38
原味好
Rank: 4
来 自:西安
等 级:业余侠客
帖 子:59
专家分:250
注 册:2011-11-29
收藏
得分:0 
等高手把
2011-12-05 19:49
快速回复:求本程序正解,以及为什么
数据加载中...
 
   



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

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