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 556431
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T11:55:08+00:00 2026-05-13T11:55:08+00:00

I read the input file , which has 911 lines , and want to

  • 0

I read the input file , which has 911 lines , and want to copy these 911 lines into the output file , after making a few changes to each line..

I am getting segmentation fault when i run this.. I dont know why.. can anyone please help..

#include<stdio.h>
void main()
{
    int i;
    FILE *fin,*fop;char* str;
    fin=fopen("atk561011.txt","r");
    if(fin=NULL) printf("ip err");
    fop=fopen("svmip.txt","w");
    if(fop=NULL) printf("op err");
    for(i=1;i<=911;i++)
    {
        fgets(str,150,fin);
        if((i>300&&i<=360)||(i>600&&i<=660)) 
            str[7]='1';
        else 
            str[7]='0';
        fputs(str+7,fop);
        putc('\n',fop);
    }
    fclose(fin);
    fclose(fop);
}
  • 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-13T11:55:08+00:00Added an answer on May 13, 2026 at 11:55 am

    For a start, this is wrong:

    if(fin=NULL)
    

    Should be:

    if (fin == NULL)
    

    (the same goes for fop, of course). And if you didn’t succeed opening the file – don’t just print an error, exit, because what are you going to read from? Keep in mind that the output of printf is buffered and in case of a segfault you won’t always see it at all, even if it ran before the fault.

    Another thing: you don’t allocate memory for str, yet write into it with fgets.

    And another thing: reading a pre-defined amount of lines from the file is probably a bad idea. It’s better to read from the input until there is an end of file, or until a required amount of lines has been read.

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

Sidebar

Related Questions

I would like to read a text file and input its contents into an
I want to read the file path from html input type=file (the entry selected
I'm trying to read and handle a web-page in Python which has lines like
I have a text file which is read in. It has delimeters which are
I have a text file (c:\input.txt) which has: 2.0 4.0 8.0 16.0 32.0 64.0
How do i read the following file which has columns of data with header
I am trying to read a file which is selected using an input type
there is a text file which we read from it , then we want
I am trying to read in an input file 64 bits at a time,
I am trying to read values from an input file in Perl. Input file

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.