"Segment Violation" error, fopen("r+")

This is a discussion on "Segment Violation" error, fopen("r+") within the C Programming forums, part of the General Programming Boards category; Hello, When I'm trying to write on a file the following program gives an error with gcc 4.5.1 on fedora ...

  1. #1
    Registered User
    Join Date
    Mar 2011
    Posts
    1

    "Segment Violation" error, fopen("r+")

    Hello,

    When I'm trying to write on a file the following program gives an error with gcc 4.5.1 on fedora and gcc 4.1.2 on centos 5.5.
    I think it is correct because I got it from a book.


    PHP Code:
    #include <stdio.h> 
    int main int argcchar **argv 

    FILE *fp
    char caracter
    fp fopen "fichero.txt""r+" ); 
    printf("\ntype the text on file: "); 
    while((
    caracter getchar()) != '\n'

    printf("%c"fputc(caracterfp)); 

    fclose fp ); 
    return 
    0


    ->gcc xxxx.c -o xxxx
    ->./xxxx

    "Segment Violation" ('core' generated)


    Thank you very much!

  2. #2
    Registered User
    Join Date
    Apr 2008
    Posts
    90
    The return value of fopen() isn't being checked. Does the file fichero.txt exist, and is it readable?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. "Segment fault?"
    By kinghajj in forum C Programming
    Replies: 5
    Last Post: 09-28-2003, 10:41 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21