簡體   English   中英

進程退出,返回值 3221225477

[英]Process exited with return value 3221225477

我正在寫這段代碼:

#include<stdio.h>
#include<stdlib.h>
int main()
{
FILE *fp;
int i;
fp = fopen("keimeno.txt","r");
fscanf(fp,"%d",i);
printf("%d\n",i);
    fclose(fp);
return 0;
}

該文件包含:

2
Yiannis Ioannou 356
3
Today
10347
If
345
And then none
1542
John Smith 743
2
My story
3940
Feedback
682
END

當我嘗試運行它時,它會退出我的值3221225477而不是打印數字 2..

誰能解釋為什么?

掃描數字時,需要在要存儲結果的地方傳遞變量的地址:

fscanf(fp,"%d",&i);

你在哪里

fscanf(fp,"%d",i);
               ^  missing the & sign!

您的編譯器確實應該發出警告-編譯時是否啟用警告?

這里發生的是fscanf函數寫入給定的位置(在您的情況下,它寫入i 指向的任何位置,而不是寫入i位置 )。 這會以各種令人討厭的方式破壞您的內存-在您的情況下,導致程序“運行”相當長的時間才崩潰。

正如@Brandin指出的那樣,您的代碼還有另一個問題(盡管不太可能成為問題的根源)。 嘗試打開文件時,應始終檢查是否成功。 您可以使用以下方法執行此操作:

#include <assert.h>
// at the top of the program


// attempt to open the file:
fp = fopen("keimeno.txt","r");
// and check whether you succeeded:
assert(fp != NULL); // this says "check fp is not NULL. Otherwise, quit."

另外,您可以使用以下方法使事情更漂亮:

const char *fileName = "keimeno.txt";
const char *mode = "r";
if((fp=fopen(fileName, mode))==NULL) {
  printf("cannot open file %s\n", fileName);
  return -1;
}

將“硬接線值”放在程序的開頭幾乎總是一個好主意,而不是將其嵌入函數調用中。

我的問題也一樣。 我清空列表,並添加了一個新值,該值導致我使用其他值輸入的值並以錯誤“ process-exited-with-return-value-3221225477”結束

#include <iostream>
#include <stdlib.h>

using namespace std;

struct Node {
   int data;
   struct Node *left;
   struct Node *right;
};
int count = 0;
struct Node*front = NULL;
struct Node*rear = NULL;

void enqueue(int val) {
    count++;
   struct Node* newnode = new Node; //= (struct Node*) malloc(sizeof(struct Node));
   newnode->data = val;
   if (front == NULL) {
        front = rear = newnode;
        newnode->right=newnode->left;
        newnode->left=newnode->right;
   }
   else {
    rear->right = newnode;
    newnode->left = rear;
    rear = newnode;
    front->left = rear;
    rear->right = front;
   }
}

void dequeue() {
   if(front==NULL)
      cout<<"There is no element yet. Cannot be dequeue."<<endl;
   else {
      if (front == rear) {
        cout<<"The dequeued element is "<< front->data <<endl;
        front = rear = NULL;
         delete front;
         }
      else {
      cout<<"The dequeued element is "<< front->data <<endl;
       struct Node *curr = front;
       front = front->right;
       front->left = rear;
       rear->right = front;
       delete curr;

       }
   }
}

void display() {
   int i;
   struct Node* ptr;

   if(front==NULL) {
      cout<<"The List is empty, nothing to display.";
      cout<<endl;
      return;
  }    
      ptr = front;
      cout<<"Element/s : ";
      for (i=0;i<count; i++) {
         cout<< ptr->data <<" ";
         ptr = ptr->right;
     }
        if (ptr->right==rear) {
            cout<< ptr->data << " ";
        }
       cout<<endl;
}

int main() {
   int ch, val;
   cout<<"1) Enqueue"<<endl;
   cout<<"2) Dequeue"<<endl;
   cout<<"3) Display"<<endl;
   cout<<"4) Exit"<<endl;
   do {
      cout<<"Enter your choice: "<<endl;
      cin>>ch;
      switch(ch) {
         case 1: {
            cout<<"Enter the value of the element:"<<endl;
            cin>>val;
            enqueue(val);
            cout<<endl;
            return main();
            break;
         }
         case 2: {
            dequeue();
            cout<<endl;
            return main();
            break;
         }
         case 3: {
            display();
            cout<<endl;
            return main();
            break;
         }
         case 4: {
            cout<<"Exit"<<endl;
            break;
         }
         default: {
            cout<<"Invalid Choice"<<endl;
         }
      }
   }while(ch!=4);
      return 0;
}

伙計,我非常感謝您發布此消息。 我已經有一段時間沒有使用 scanf 了,它讓我免於浪費時間試圖找出問題所在並逐步調試。 太棒了! 這甚至不是我第一次訪問那個博客

exited_return_value-3221225477是由於各個編譯器的gnu邏輯錯位導致的編譯器代碼錯誤的高度抽象錯位。同一代碼將在另一個系統中執行。該值稱為系統調用()錯誤...

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM