Thread: surprise..another not working code.

  1. #1
    Registered User
    Join Date
    Dec 2010
    Posts
    20

    surprise..another not working code.

    What's wrong fellows?

    #include<stdio.h>

    main()

    {

    FILE *pt1;
    char c;
    printf("data input output");
    pt1=fopen("data.txt","w");
    while((c=getchar())=!EOF)
    putc(c,pt1);
    fclose(pt1);

    printf("\ndata input");
    pt1=fopen("data.txt","r");
    while(c=getc(pt1)!=EOF)
    printf("%c",c);
    fclose(pt1);

    }

  2. #2
    Registered User
    Join Date
    May 2010
    Location
    Naypyidaw
    Posts
    1,314
    Code:
    while(c=getc(pt1)!=EOF)
    Pay attention to precedence comparison != and assignment =.
    getc/getchar() returns int.
    Question 12.1
    Use code tag.

  3. #3
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    What's wrong is that you didn't post the compiler error messages.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Code working but not after 1 day
    By sheepilja in forum C Programming
    Replies: 3
    Last Post: 12-12-2010, 10:37 AM
  2. annoying bugs on working code
    By sammyfallows in forum C++ Programming
    Replies: 5
    Last Post: 11-20-2010, 09:05 PM
  3. Replies: 3
    Last Post: 02-24-2009, 08:49 PM
  4. C code not working
    By D3ciph3r in forum C Programming
    Replies: 2
    Last Post: 05-27-2005, 04:13 PM
  5. Trying to eject D drive using code, but not working... :(
    By snowfrog in forum C++ Programming
    Replies: 3
    Last Post: 05-07-2005, 07:47 PM