| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 710 人关注过本帖
标题:编写程序时,编译过不了,求指点
只看楼主 加入收藏
yl101010
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2016-12-17
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:2 
编写程序时,编译过不了,求指点
//扫雷//
#include <stdio.h>
#include <stdlib.h>
int main()
{
    int sl(int i,int m,int n,char b[]);
    int p,q,i,j,m,n;
    char b[100][100];
    for(i=0;i<100;i++)   
     {
         scanf("%d %d\n",&p,&q); //输入两个数                                 
         if(p==0||q==0)
         {
           break;   
         }
        else
        {           //输入地雷图
         for(m=0;m<p;m++)
          {
           for(n=0;n<q;n++)
           {
              scanf("%c",&b[m][n]);
           }
           printf("\n");
          }
        int sl(i,p,q,b); //扫雷函数
        }
     }
    return 0;
}


int sl(int i,int m,int n,char b[m][n])
{
    int j,k;
    char c[m][n];
    int t=0,s=0;
    int x,y;
   
   
    for(j=0;j<m;j++)                //扫雷中
    {
        for(k=0;k<n;k++)
        {
            x=(j>0&&j<m-1)?1:((j==0)?0:2); //判断位置
            y=(k>0&&k<n-1)?1:((k==0)?0:2);
            switch(x)
            {  
                case 0:switch(y)     //计算周围地雷数
                       {
                        case 0:if(b[j][k]=='*')
                               {
                                   c[j][k]='*';
                               }
                               else
                               {
                                   if(j+1<m)
                                   {
                                       s++;
                                       if(b[j+1][k]=='*')
                                       {
                                           t++;
                                    }
                                }
                                if(k+1<n)
                                {
                                    s++;
                                    if(b[j+1][k]=='*')
                                       {
                                           t++;
                                    }
                                }
                                if(s==2)
                                {
                                    if(b[j+1][k+1]=='*')
                                    {
                                        t++;
                                    }
                                }
                                c[j][k]=(char)(t+48);
                                s=0;
                                t=0;
                               }break;
                        case 1:if(b[j][k]==*)
                               {
                                   c[j][k]='*';
                               }
                               else
                               {
                                   if(j+1<m)
                                   {
                                       s++;
                                       if(b[j+1][k]=='*')
                                       {
                                           t++;
                                    }
                                    if(b[j+1][k-1]=='*')
                                       {
                                           t++;
                                    }
                                    if(b[j+1][k+1]=='*')
                                       {
                                           t++;
                                    }
                                }
                                if([j][k-1]=='*')
                                {
                                    t++;
                                }
                                if(b[j][k+1]=='*')
                                   {
                                       t++;
                                }
                                c[j][k]=(char)(t+48);
                                s=0;
                                t=0;
                               }break;
                        case 2:if(b[j][k]==*)
                               {
                                   c[j][k]='*';
                               }
                               else
                               {
                                   if(j+1<m)
                                   {
                                       s++;
                                       if(b[j+1][k]=='*')
                                       {
                                           t++;
                                    }
                                }
                                if(b[j][k-1]=='*')
                                {
                                    t++;
                                }
                                if(s==1)
                                {
                                    if(b[j-1][k-1]=='*')
                                    {
                                        t++;
                                    }
                                }
                                c[j][k]=(char)(t+48);
                                s=0;
                                t=0;
                               }break;
                        default:printf("error.\n");
                       }break;
                case 1:switch(y)
                       {
                        case 0:if(b[j][k]==*)
                               {
                                   c[j][k]='*';
                               }
                               else
                               {
                                   if(k+1<n)
                                   {
                                       s++;
                                       if(b[j-1][k+1]=='*')
                                       {
                                           t++;
                                    }
                                    if(b[j][k+1]=='*')
                                       {
                                           t++;
                                    }
                                    if(b[j+1][k+1]=='*')
                                       {
                                           t++;
                                    }
                                }
                                if([j-1][k]=='*')
                                {
                                    t++;
                                }
                                if(b[j+1][k]=='*')
                                   {
                                       t++;
                                }
                                c[j][k]=(char)(t+48);
                                s=0;
                                t=0;
                               }break;
                        case 1:if(b[j][k]==*)
                               {
                                   c[j][k]='*';
                               }
                               else
                               {
                                   if(b[j-1][k-1]=='*')
                                   {
                                       t++;
                                }
                                   if(b[j-1][k]=='*')
                                   {
                                       t++;
                                }
                                if(b[j-1][k+1]=='*')
                                   {
                                       t++;
                                }
                                if(b[j][k-1]=='*')
                                   {
                                       t++;
                                }
                                if([j][k+1]=='*')
                                {
                                    t++;
                                }
                                if(b[j+1][k-1]=='*')
                                   {
                                       t++;
                                }
                                if(b[j+1][k]=='*')
                                   {
                                       t++;
                                }
                                if(b[j+1][k+1]=='*')
                                   {
                                       t++;
                                }
                                c[j][k]=(char)(t+48);
                                s=0;
                                t=0;
                               }break;
                        case 2:if(b[j][k]==*)
                               {
                                   c[j][k]='*';
                               }
                               else
                               {
                                   if(b[j-1][k-1]=='*')
                                   {
                                       t++;
                                }
                                   if(b[j-1][k]=='*')
                                   {
                                       t++;
                                }
                                if(b[j][k-1]=='*')
                                   {
                                       t++;
                                }
                                if(b[j+1][k-1]=='*')
                                   {
                                       t++;
                                }
                                if(b[j+1][k]=='*')
                                   {
                                       t++;
                                }
                                c[j][k]=(char)(t+48);
                                s=0;
                                t=0;
                               }break;
                        default:printf("error.\n");
                       }break;
                case 2:switch(y)
                       {
                        case 0:if(b[j][k]==*)
                               {
                                   c[j][k]='*';
                               }
                               else
                               {
                                   if(k+1<n)
                                   {
                                       s++;
                                       if(b[j-1][k]=='*')
                                       {
                                           t++;
                                    }
                                    if(b[j-1][k+1]=='*')
                                       {
                                           t++;
                                    }
                                    if(b[j][k+1]=='*')
                                       {
                                           t++;
                                    }
                                }
                                c[j][k]=(char)(t+48);
                                s=0;
                                t=0;
                               }break;
                        case 1:if(b[j][k]==*)
                               {
                                   c[j][k]='*';
                               }
                               else
                               {
                                   if(b[j-1][k-1]=='*')
                                   {
                                       t++;
                                }
                                   if(b[j-1][k]=='*')
                                   {
                                       t++;
                                }
                                if(b[j-1][k+1]=='*')
                                   {
                                       t++;
                                }
                                if(b[j][k-1]=='*')
                                   {
                                       t++;
                                }
                                if(b[j][k+1]=='*')
                                   {
                                       t++;
                                }
                                c[j][k]=(char)(t+48);
                                s=0;
                                t=0;
                               }break;
                        case 2:if(b[j][k]==*)
                               {
                                   c[j][k]='*';
                               }
                               else
                               {
                                   if(b[j-1][k-1]=='*')
                                   {
                                       t++;
                                }
                                   if(b[j-1][k]=='*')
                                   {
                                       t++;
                                }
                                if(b[j][k-1]=='*')
                                   {
                                       t++;
                                }
                                c[j][k]=(char)(t+48);
                                s=0;
                                t=0;
                               }break;
                        default:printf("error.\n");
                       }break;
                default:printf("error.\n");
            }
        }
    }
   
   
    for(j=0;j<m;j++)   //输出扫雷图
      {
           printf("Field #%d:\n",i);
        for(k=0;k<n;k++)
        {
          printf("%c",c[j][k]);   
        }
        printf("\n");
      }
return 0;
}












搜索更多相关主题的帖子: 编写程序 include 
2016-12-17 14:40
九转星河
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:长长久久
等 级:贵宾
威 望:52
帖 子:5023
专家分:14003
注 册:2016-10-22
收藏
得分:15 
按编译器报错慢慢找问题~问题主要是对变量的疏忽而引起的~
主要是声明和引用变量的问题~可以正常运行,但里面的功能要题主自己慢慢调试~
程序代码:
#include <stdio.h>
#include <stdlib.h>
int main() 
{
    int sl(int i,int m,int n,char b[][100]);
    int p,q,i,m,n;
    char b[100][100];
    for(i=0;i<100;i++)   
     {
         scanf("%d %d\n",&p,&q); //输入两个数                                 
         if(p==0||q==0)
         {
           break;    
         }
        else
        {           //输入地雷图
         for(m=0;m<p;m++)
          {
           for(n=0;n<q;n++)
           {
              scanf("%c",&b[m][n]);
           }
           printf("\n"); 
          }
         sl(i,p,q,b); //扫雷函数 
        }
     }
    return 0;
}


int sl(int i,int m,int n,char b[][100])
{
    int j,k;
    char c[100][100];
    int t=0,s=0;
    int x,y;
    
    
    for(j=0;j<m;j++)                //扫雷中
    {
        for(k=0;k<n;k++)
        {
            x=(j>0&&j<m-1)?1:((j==0)?0:2); //判断位置 
            y=(k>0&&k<n-1)?1:((k==0)?0:2);
            switch(x)
            {  
                case 0:switch(y)     //计算周围地雷数 
                       {
                        case 0:if(b[j][k]=='*')
                               {
                                   c[j][k]='*';
                               }
                               else
                               {
                                   if(j+1<m)
                                   {
                                       s++;
                                       if(b[j+1][k]=='*')
                                       {
                                           t++;
                                    }
                                }
                                if(k+1<n)
                                {
                                    s++;
                                    if(b[j+1][k]=='*')
                                       {
                                           t++;
                                    }
                                }
                                if(s==2)
                                {
                                    if(b[j+1][k+1]=='*')
                                    {
                                        t++;
                                    }
                                }
                                c[j][k]=(char)(t+48);
                                s=0;
                                t=0;
                               }break;
                        case 1:if(b[j][k]=='*')//
                               {
                                   c[j][k]='*';
                               }
                               else
                               {
                                   if(j+1<m)
                                   {
                                       s++;
                                       if(b[j+1][k]=='*')
                                       {
                                           t++;
                                    }
                                    if(b[j+1][k-1]=='*')
                                       {
                                           t++;
                                    }
                                    if(b[j+1][k+1]=='*')
                                       {
                                           t++;
                                    }
                                }
                                if(b[j][k-1]=='*')//
                                {
                                    t++;
                                }
                                if(b[j][k+1]=='*')
                                   {
                                       t++;
                                }
                                c[j][k]=(char)(t+48);
                                s=0;
                                t=0;
                               }break;
                        case 2:if(b[j][k]=='*')//
                               {
                                   c[j][k]='*';
                               }
                               else
                               {
                                   if(j+1<m)
                                   {
                                       s++;
                                       if(b[j+1][k]=='*')
                                       {
                                           t++;
                                    }
                                }
                                if(b[j][k-1]=='*')
                                {
                                    t++;
                                }
                                if(s==1)
                                {
                                    if(b[j-1][k-1]=='*')
                                    {
                                        t++;
                                    }
                                }
                                c[j][k]=(char)(t+48);
                                s=0;
                                t=0;
                               }break;
                        default:printf("error.\n");
                       }break;
                case 1:switch(y)
                       {
                        case 0:if(b[j][k]=='*')//
                               {
                                   c[j][k]='*';
                               }
                               else
                               {
                                   if(k+1<n)
                                   {
                                       s++;
                                       if(b[j-1][k+1]=='*')
                                       {
                                           t++;
                                    }
                                    if(b[j][k+1]=='*')
                                       {
                                           t++;
                                    }
                                    if(b[j+1][k+1]=='*')
                                       {
                                           t++;
                                    }
                                }
                                if(b[j-1][k]=='*')
                                {
                                    t++;
                                }
                                if(b[j+1][k]=='*')
                                   {
                                       t++;
                                }
                                c[j][k]=(char)(t+48);
                                s=0;
                                t=0;
                               }break;
                        case 1:if(b[j][k]=='*')
                               {
                                   c[j][k]='*';
                               }
                               else
                               {
                                   if(b[j-1][k-1]=='*')
                                   {
                                       t++;
                                }
                                   if(b[j-1][k]=='*')
                                   {
                                       t++;
                                }
                                if(b[j-1][k+1]=='*')
                                   {
                                       t++;
                                }
                                if(b[j][k-1]=='*')
                                   {
                                       t++;
                                }
                                if(b[j][k+1]=='*')//
                                {
                                    t++;
                                }
                                if(b[j+1][k-1]=='*')
                                   {
                                       t++;
                                }
                                if(b[j+1][k]=='*')
                                   {
                                       t++;
                                }
                                if(b[j+1][k+1]=='*')
                                   {
                                       t++;
                                }
                                c[j][k]=(char)(t+48);
                                s=0;
                                t=0;
                               }break;
                        case 2:if(b[j][k]=='*')
                               {
                                   c[j][k]='*';
                               }
                               else
                               {
                                   if(b[j-1][k-1]=='*')
                                   {
                                       t++;
                                }
                                   if(b[j-1][k]=='*')
                                   {
                                       t++;
                                }
                                if(b[j][k-1]=='*')
                                   {
                                       t++;
                                }
                                if(b[j+1][k-1]=='*')
                                   {
                                       t++;
                                }
                                if(b[j+1][k]=='*')
                                   {
                                       t++;
                                }
                                c[j][k]=(char)(t+48);
                                s=0;
                                t=0;
                               }break;
                        default:printf("error.\n");
                       }break;
                case 2:switch(y)
                       {
                        case 0:if(b[j][k]=='*')
                               {
                                   c[j][k]='*';
                               }
                               else
                               {
                                   if(k+1<n)
                                   {
                                       s++;
                                       if(b[j-1][k]=='*')
                                       {
                                           t++;
                                    }
                                    if(b[j-1][k+1]=='*')
                                       {
                                           t++;
                                    }
                                    if(b[j][k+1]=='*')
                                       {
                                           t++;
                                    }
                                }
                                c[j][k]=(char)(t+48);
                                s=0;
                                t=0;
                               }break;
                        case 1:if(b[j][k]=='*')//
                               {
                                   c[j][k]='*';
                               }
                               else
                               {
                                   if(b[j-1][k-1]=='*')
                                   {
                                       t++;
                                }
                                   if(b[j-1][k]=='*')
                                   {
                                       t++;
                                }
                                if(b[j-1][k+1]=='*')
                                   {
                                       t++;
                                }
                                if(b[j][k-1]=='*')
                                   {
                                       t++;
                                }
                                if(b[j][k+1]=='*')
                                   {
                                       t++;
                                }
                                c[j][k]=(char)(t+48);
                                s=0;
                                t=0;
                               }break;
                        case 2:if(b[j][k]=='*')//
                               {
                                   c[j][k]='*';
                               }
                               else
                               {
                                   if(b[j-1][k-1]=='*')
                                   {
                                       t++;
                                }
                                   if(b[j-1][k]=='*')
                                   {
                                       t++;
                                }
                                if(b[j][k-1]=='*')
                                   {
                                       t++;
                                }
                                c[j][k]=(char)(t+48);
                                s=0;
                                t=0;
                               }break;
                        default:printf("error.\n");
                       }break;
                default:printf("error.\n");
            }
        }
    }
    
    
    for(j=0;j<m;j++)   //输出扫雷图 
      {
           printf("Field #%d:\n",i);
        for(k=0;k<n;k++)
        {
          printf("%c",c[j][k]);    
        }
        printf("\n");
      }
return 0;
}

[code]/*~个性签名:bug是什么意思?bug是看上去没有可能的东西实际上是有可能做到的 就是这样~2018-08-08更~*/[/code]
2016-12-17 14:52
yangfrancis
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:贵宾
威 望:141
帖 子:1510
专家分:7661
注 册:2014-5-19
收藏
得分:5 
怎么没有看到对用户输入事件的处理。
2016-12-17 18:20
快速回复:编写程序时,编译过不了,求指点
数据加载中...
 
   



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

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