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

  • Home
  • SEARCH
  • 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 6025265
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T04:16:33+00:00 2026-05-23T04:16:33+00:00

I am following the C programming tutorial at http://www.cprogramming.com/tutorial/c/lesson10.html . This particular tutorial teaches

  • 0

I am following the C programming tutorial at http://www.cprogramming.com/tutorial/c/lesson10.html. This particular tutorial teaches file I/O in C; in particular, the fopen command is discussed. At one point, they give the following example (which I think should print the contents of file test.txt):

FILE *fp;
fp=fopen("c:\\test.txt", "w");
fprintf(fp, "Testing...\n");

So, I made a text file called test.txt and saved it in my current, working directory (C:\cygwin\home\Andrew\cprogramming). Then I created a c file in this same directory, and it contains the following code:

#include <stdio.h>

int main()
{
  FILE *fp;
  fp=open("test.txt","w");
  fprintf(fp,"Testing...\n");
}

When I compile this c file (which I’ve called helloworld2.c) using gcc, I get the following messages:

helloworld2.c: In function `main':
helloworld2.c:40: warning: assignment makes pointer from integer without a cast

Then when I try to run the executable, I get:

Segmentation fault (core dumped)

Do you have any ideas about what I should try next?

Thank you very much for your time.

  • 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-23T04:16:34+00:00Added an answer on May 23, 2026 at 4:16 am

    This is because you use open instead of fopen. Open is from the POSIX standard and returns an (integer) handle; fopen returns the memory address of a FILE structure. You cannot use both in an interchangeable way. As it stands, your code implicitly casts the received integer (likely 4) to a FILE* pointer, making it point to the memory address 4. This segfaults your program when fprintf attempts to access it.

    fopen is cross-platform, but open is POSIX-only. You may want to stick to fopen for now.

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

Sidebar

Related Questions

http://docs.djangoproject.com/en/dev/intro/tutorial03/ I was at the step Decoupling the URLconfs where the tutorial illustrates how
I was reading through this Advanced Linux Programming tutorial when I encountered a problem.
Following up on this question: Kiosk Applications - OS X programming - Multiple monitors
I'm following the sample code in CFNetwork Programming Guide , specifically the section on
In his The C++ Programming Language Stroustrup gives the following example for inc/dec overloading:
I read the following in a review of Knuth's The Art of Computer Programming:
I am novice in sharepoint programming. I have a following code: SPWorkflowTask task =
Following this question: Good crash reporting library in c# Is there any library like
Following on from this question what would be the best way to write a
I know this isn't exactly a programming question per se, but rather a settings

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.