简体   繁体   English

在 turbo c++ 上执行程序后出错(在 output 屏幕上)

[英]Error after executing program at turbo c++(at output screen)

#include <stdio.h> 
#include<stdlib.h> 
#include<conio.h> 
//to generate numbers 
 void gen_data(int b[], int n) 
  { 

     int i;
     for(i=0;i<n;i++) 
     b[i]=rand()%101; 
   } 
   //to display numbers 
     
void disp_data(intb[],intn) 
{ 
  int i;
  for(i=0;i<n;i++) 
  printf("%d \n",b[i]); 
} 
//insert at desired posn 
void insert(int b[], int n, int 
 elt, int pos) 
{ 
 int i; 
  for(i=n-1; i>=pos;i--) 
  b[i+1]=b[i]; 
  b[pos]=elt; 
    } 
//delete an elt at given 
  positionn 
   void delete(int b[], int n, 
 int pos) 
    { 
  int i; 
 for(i=pos+1;i<n;i++) 
  b[i-1]=b[i]; 
  } 
//driver code 
void main() 
{ 
 int a[100], pos, n=10, elt; 
  int opt; 
  clrscr(); 
  gen_data(a,n);

 while (1) 

  { 

  printf("\n 1- Insert 2-Delete 
    3-Display 4-quit\n"); 
   scanf("%d",&opt); 
   switch(opt) 
    { 
     case 1: printf(" Enter 
      positionn & elt to be 
        insertedd: "); 
         scanf("%d %d", &pos, 
          &elt); 
         insert(a,n,elt,pos); 
          n++; 
         break; 
          case 2: printf("enter 
          positionn at which 
        eltt to be deleted: "); 
        scanf("%d",pos); 
          delete(a,n,pos); 
            n--; 
         break; 
         case 3: printf("the 
         numbers are : \n"); 
       disp_data(a,n); 
       break; 
       } 
        if (opt==4) break; 
        } //end while
     }

when i run my code in turbo c++ it shows no errors but at output screen after excuting program and now turn to give values it will come back to codding screen.当我在 turbo c++ 中运行我的代码时,它没有显示任何错误,但是在执行程序后在 output 屏幕上,现在转向给出值,它将返回到编码屏幕。 I tried to put getch() but after giving one valve it returned to codding screen.我试图放置 getch() 但在给出一个阀门后它返回到编码屏幕。 If I tried to display elements it will display random elements如果我尝试显示元素,它将显示随机元素

You have got plenty of errors in the code:您的代码中有很多错误:

  1. This declaration:这个声明:

     void disp_data(intb[], intn)

    is clearly invalid.显然是无效的。 Adding space between int and b[] will solve this.intb[]之间添加空格将解决这个问题。 Same with the other parameter.与其他参数相同。

  2. In this declaration:在此声明中:

     positionn void delete (int b[], int n, int pos)

    You cannot use two types in the return statement, despite mentioning void in there.你不能在 return 语句中使用两种类型,尽管在那里提到了void I think you assume you may not want to return anything since you're trying to modify the array.我想你假设你可能不想返回任何东西,因为你正在尝试修改数组。 So, remove positionn .所以,删除positionn

  3. This syntax (defined in the 2nd case statement):此语法(在第二个 case 语句中定义):

     scanf("%d", pos);

    You forgot to introduce an ampersand sign to point-to its address.你忘了引入一个符号来指向它的地址。 Change that into &pos .将其更改为&pos

  4. Turbo-C is ancient. Turbo-C 很古老。 In fact, it's outdated.事实上,它已经过时了。 The main() must return an integer, at least zero after a successful execution. main()必须返回 integer,成功执行后至少为零。 Replace the main() structure like this:像这样替换main()结构:

     int main(void) {. . return 0; }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM