| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1451 人关注过本帖
标题:代码编译不出来,求指教
只看楼主 加入收藏
屋顶
Rank: 1
等 级:新手上路
帖 子:174
专家分:7
注 册:2016-2-27
结帖率:92.86%
收藏
 问题点数:0 回复次数:2 
代码编译不出来,求指教
#include<stdio.h>
#include<Ctype.h>
#include<string.h>
#define MAX 40
#define ANSWER "Grant"
main()
{
    char try[MAX];
    puts("Who is buried in Grant's tomb?");
    gets(try);
   toupper(ANSWER);
   toupper(try);
    while(strcmp(try,ANSWER)!=0)
       {
           puts("No,that's wrong.Try again.");
           gets(try);
           }
   puts("That's right!");
    }
如上代码编译不出来,编译信息如下:
g++.exe  -x c++ -c E:\编程\c文件\iiiii -o E:\编程\c文件\iiiii.o  -Wall -fpermissive  -Wno-sign-compare -g
E:\编程\c文件\iiiii:7: warning: ISO C++ forbids declaration of `main' with no type
E:\编程\c文件\iiiii: In function `int main()':
E:\编程\c文件\iiiii:8: error: expected primary-expression before "char"
E:\编程\c文件\iiiii:8: error: expected `;' before "char"
E:\编程\c文件\iiiii:10: error: expected primary-expression before "try"
E:\编程\c文件\iiiii:11: warning: invalid conversion from `const char*' to `int'
E:\编程\c文件\iiiii:11: warning:   initializing argument 1 of `int toupper(int)'
E:\编程\c文件\iiiii:12: error: expected primary-expression before "try"
E:\编程\c文件\iiiii:13: error: expected primary-expression before "try"
E:\编程\c文件\iiiii:16: error: expected primary-expression before "try"
Failure
求大神指教,谢谢
搜索更多相关主题的帖子: 信息 include 
2016-04-21 17:01
alice_usnet
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:贵宾
威 望:18
帖 子:370
专家分:2020
注 册:2016-3-7
收藏
得分:0 
程序代码:
#include<stdio.h>
#include<ctype.h>
#include<string.h>
#define MAX 40
#define ANSWER "Grant"
main()
{
   char try[MAX];
   puts("Who is buried in Grant's tomb?");
   gets(try);
   char p[10]=ANSWER;
   void conversion(char *p);
   conversion(try);
   conversion(p);
   /*toupper(ANSWER);*/
   /*toupper(try);*/
   while(strcmp(try,ANSWER)!=0)
   {
      puts("No,that's wrong.Try again.");
      gets(try);
      conversion(try);
   }
   puts("That's right!");
}

void conversion(char *p)
{
  int i;
  for(i=0;p[i]!='\0';i++)
    p[i]=toupper(p[i]);
}

未佩好剑,转身便已是江湖
2016-04-21 19:33
qq1023569223
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:湖南科技大学
等 级:贵宾
威 望:26
帖 子:2753
专家分:13404
注 册:2010-12-22
收藏
得分:0 
程序代码:
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#define MAX 40
#define ANSWER "GRANT"  //Don't make change to const value

void UP(char s[])
{
    int len=strlen(s);
    int i;

    for(i=0;i<len;++i)
    {
        s[i]=toupper(s[i]);  //The function toupper use to uppercase only one char
    }
}

int main()  //main must have a return value
{
    char try[MAX];
    puts("Who is buried in Grant's tomb?");
    gets(try);
    UP(try);
    while(strcmp(try,ANSWER)!=0)
    {
        puts("No,that's wrong.Try again.");
        gets(try);
        UP(try);  //Must uppercase again
    }
   puts("That's right!");

   return 0;
}

   唯实惟新 至诚致志
2016-04-21 19:34
快速回复:代码编译不出来,求指教
数据加载中...
 
   



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

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