Thread: homework time

  1. #1
    cereal killer dP munky's Avatar
    Join Date
    Nov 2002
    Posts
    655

    homework time

    im wanting to read in from 1 text file, and write to another, i want to take an ALL CAPS file

    ex) THIS IS MY FILE IT IS A BUNCH OF CRAP. BLAH
    BLAH BLAH, BLAH BLAH, BLAH BLAH!!!

    and write it to another so that it looks like this

    ex)This is my file it is a bunch of crap Blah
    blah blah, blah blah, blah blah!!!

    i wrote it, and im getting some wierd errors, im wanting to stick with stdio.h. but like i said, im getting some wierd errors...can you guys check out my code??

    THANKS!
    ****************
    Code:
    #include <stdio.h>
    
    int UPPERtoLOWER(int ch);
    void SearchString(char *sentence);
    
    int i = 0;
    
    int main()
    {
    	char sentence[500];
    	FILE *rptPTR;   /* file pointer to the report*/
    	FILE *updatePTR;   /* file pointer to the updated file*/
    
    	if (( rptPTR = fopen("report.txt", "r") ) == NULL )
    	{
    		printf("File could not be opened!\n");
    	}
    
    	if (( updatePTR = fopen("update.txt", "w") ) == NULL )
        {
    		printf("File could not be opened!\n");
        }
    	
    	else 
    	{
    		while(fgets(sentence, 500, rptPTR) != NULL)
    		{
    			printf("%s", sentence);
    		}
    
    		printf("\n");
    		
    		if (( updatePTR = fopen("update.txt", "w") ) == NULL )
    		{
    			printf("File could not be opened!\n");
    		}
    		
    		else
    		{
    			 
    
    			SearchString(sentence);
    			fwrite(sentence, sizeof(char), sizeof(sentence), updatePTR);
    		}
    		
    		fclose(rptPTR);
    		fclose(updatePTR);
    
    		printf("Your file has been updated!\nLook for update.txt\n");
    	}
    
    	return 0;
    }
    
    
    int UPPERtoLOWER(int ch)
    {
       if (( 'A' <= ch) && (ch <= 'Z' ))
       {
            return (ch - 'A' + 'a');
       }
    
       else
       {
            return ch;
       }
    }
    
    
    void SearchString(char *sentence)
    {
      char space = ' ';
      char period = '.';
      char exclam = '!';
      char questmk = '?';
      static int C=1;
    
      for (i = 0; sentence[i] != '\0'; i++)
      {
           if ((sentence[i] == period) || (sentence[i] == exclam) || (sentence[i] == questmk))
           {
              C=1;
           }
           if( C && 'A' <= sentence[i] && sentence[i] <= 'Z' ){
               C=0;
           }else{
               sentence[i] =(char)UPPERtoLOWER(sentence[i]);
           }
      }
    }
    guns dont kill people, abortion clinics kill people.

  2. #2
    Registered User
    Join Date
    Nov 2002
    Posts
    491
    Is it just me, or does Krush's post resemble this one alot??

  3. #3
    Registered User
    Join Date
    Oct 2002
    Posts
    57
    Same class.

  4. #4
    cereal killer dP munky's Avatar
    Join Date
    Nov 2002
    Posts
    655
    we got it taken care of guys. Thanks!

    and for the record, colaboration isnt cheating, sharing code however is.
    guns dont kill people, abortion clinics kill people.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Using pointers
    By Big_0_72 in forum C Programming
    Replies: 3
    Last Post: 10-28-2008, 07:51 PM
  2. Journey time prog 1 minute wrong
    By mike_g in forum C Programming
    Replies: 4
    Last Post: 10-12-2006, 03:41 AM
  3. The Timing is incorret
    By Drew in forum C++ Programming
    Replies: 5
    Last Post: 08-28-2003, 04:57 PM
  4. calculating user time and time elapsed
    By Neildadon in forum C++ Programming
    Replies: 0
    Last Post: 02-10-2003, 06:00 PM