flle

i m getting segmentation fault in a file copy program .give me some su

Page 1 of 1

3 Replies - 526 Views - Last Post: 28 January 2010 - 04:24 PM Rate Topic: -----

#1 kun87al  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 17-January 10

flle

Posted 28 January 2010 - 06:35 AM

#include<stdio.h>
//#include<string.h>
main()
{
FILE *fs,*ft;
char ch;
fs=fopen("PR1.c","r");
if(fs=NULL){
        printf("\n\t can't open the source file\n");
        }
ft=fopen("PR2.c","w");
if(ft==NULL){
        printf("\n\tcan't open the  target file \n");
        fclose(fs);
        }
while(1)        
{
        ch=fgetc(fs);
        if(ch==EOF)
        break;
        else
        fputc(ch,ft);
        }

fclose(fs);
fclose(ft);
}


*** MOD EDIT: Added code tags. Please :code: ***

This post has been edited by JackOfAllTrades: 28 January 2010 - 06:43 AM


Is This A Good Question/Topic? 0
  • +

Replies To: flle

#2 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6110
  • View blog
  • Posts: 23,670
  • Joined: 23-August 08

Re: flle

Posted 28 January 2010 - 06:46 AM

if(fs=NULL){

That's assigning NULL to fs, not comparing it. Also, if that does == NULL, you continue with the program as if it's usable, and it's not.
Was This Post Helpful? 0
  • +
  • -

#3 pdkharkar  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 63
  • View blog
  • Posts: 345
  • Joined: 19-January 09

Re: flle

Posted 28 January 2010 - 06:48 AM

if(fs=NULL){



change this line to

if(fs == NULL)




this should solve the problem
because here it is not checking for the condition
what it does is just to assign the null value to the fs file pointer
Was This Post Helpful? 0
  • +
  • -

#4 Delta_Echo  Icon User is offline

  • D.I.C Addict

Reputation: 5
  • View blog
  • Posts: 722
  • Joined: 24-October 07

Re: flle

Posted 28 January 2010 - 04:24 PM

You may find this useful:http://www.cplusplus.com/doc/tutorial/operators/
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1