Thread: manipulating files in place

  1. #1
    Registered User caroundw5h's Avatar
    Join Date
    Oct 2003
    Posts
    751

    manipulating files in place

    I'm trying to understand file streams and how they work and I'm still a little frustrated as to why this code wouldn't work - without calling fseek,
    Code:
    /*manipulating files in place */
    #include <stdio.h>
    #include <stdlib.h>
    #include <ctype.h>
    int main(int argc, char *argv[]){
        int ch,lower;
        FILE *file;
    
       
        
        if ( (file = fopen(argv[1], "r+") ) == NULL){
        	puts("Unable to open file");
        	getchar();
        	return 1;
         }   
      
        	
       	while( ( ch = fgetc(file) ) != EOF){
       	    if( (isupper(ch) ) )
       	      tolower(ch); 
       	      
        }    
           
        if ( fclose(file) !=0)
           puts("Unable to close file");
           
         getchar();
         return 0;
     }
    I got this
    If the file is opened in the update mode (+), then output cannot be directly followed by input and input cannot be directly followed by output without an intervening fseek, fsetpos, rewind, or fflush.
    but why?
    Last edited by caroundw5h; 09-20-2004 at 05:45 PM.
    Warning: Opinions subject to change without notice

    The C Library Reference Guide
    Understand the fundamentals
    Then have some more fun

  2. #2
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    read this post.
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Error opening files in a different dir
    By Ozzie in forum C++ Programming
    Replies: 3
    Last Post: 10-09-2008, 06:55 AM
  2. Working with muliple source files
    By Swarvy in forum C++ Programming
    Replies: 1
    Last Post: 10-02-2008, 08:36 AM
  3. I Need To Know Some Things That I Can Put Into A Batch File
    By TheRealNapster in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 10-20-2003, 08:12 PM
  4. Using c++ standards
    By subdene in forum C++ Programming
    Replies: 4
    Last Post: 06-06-2002, 09:15 AM
  5. Manipulating 60MB files
    By nmaskell in forum C++ Programming
    Replies: 10
    Last Post: 05-08-2002, 01:14 AM