Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 336401
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T10:14:20+00:00 2026-05-12T10:14:20+00:00

can anyone tell me whats wrong in the following program that accepts 1 or

  • 0

can anyone tell me whats wrong in the following program that accepts 1 or 2 digit integers untill it encounters the number 42 after which it prints the previously entered numbers??when i upload this to the sphere online judge site it says compilation successful but runtime error (SIGSEGV).

#include <stdio.h>
int main()
{
  int i;
  FILE *fp;
  fp=fopen("\\db.txt","w+");
  if(fp==NULL)
  {
   printf("file not exitsts and cant be created");
   system("exit");
  }
  while(1)
  {
   scanf("%d",&i);
   if(i==42)
   break;
   else
   {
    fprintf(fp,"%d\n",i); 
   }    
  }
  fclose(fp);
  fp=fopen("\\db.txt","r+");
  if(fp==NULL)
  {
   printf("file not exitsts and cant be created");
   system("exit");
  }
  fscanf(fp,"%d",&i);
  printf("%d\n",i); 
  while((!feof(fp)))
  {
    fscanf(fp,"%d",&i);
    if(!feof(fp))
    printf("%d\n",i);                
  }

  fclose(fp);
  return 0;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T10:14:20+00:00Added an answer on May 12, 2026 at 10:14 am

    It seems like you’re trying to answer this: http://www.spoj.pl/problems/TEST/ . This problem certainly does not require you to read or write anything from a file, and their server may not allow you to open files on its disk. Even if it does, you’re trying to use a windows-style path (with a backslash) on what may be a non-Windows server. And even if it does allow file creation and windows-style path separation, you are trying to create your file in the filesystem root directory, and they almost certainly do not allow file creation there.

    Combined with the system("exit") issue that everyone pointed out where it doesn’t actually exit the program, this will cause you to receive a NULL file pointer and crash when you try to use it.

    Re-read the problem description – you’re over-thinking it. It doesn’t say anywhere that you have to wait until you get a 42 to print out the other numbers. All you have to do is print back what is entered until you get a 42. That should make the solution much simpler. It’s not supposed to be even a mildly challenging problem; it’s just supposed to familiarize you with their system.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can anyone tell me what's wrong with this robots.txt? http://bizup.cloudapp.net/robots.txt The following is the
following is my code, can any one tell me whats going wrong. <input type=checkbox
Can anyone tell me what is wrong with the following code? __inline__ char* ut_byte_to_long
Can anyone tell me what could be wrong with the following code! Im this
Can anyone tell me what is wrong with the following code? It adds the
Can anyone tell me what's wrong with this code? class Dataset < ActiveRecord::Base has_many
Can anyone tell me what's wrong with this code? It's giving me an error
Can anyone tell me what is wrong with this code? public abstract class BoardTestBean{
Anyone can tell me what I'm doing wrong? I am creating a simple system
Can anyone help me debug this program? The following is server code : package

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.