Thread: Stuck With C Assignment

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

    Stuck With C Assignment

    Hey,

    I need to write a program that opens a text file, removes characters such as "@, £" etc which are placed in the middle of words, when an "i" occurs on its own, change it to a capital "I", change the first letter of each sentence to a capital (after every full stop has to be a capital), and then finally write the edited file to a new file

    I'm able to write code that opens the existing file and writes it to a new one, however i dont know where to start on writing code to edit the text, i believe that if statements and loops are needed (?)

    I'm a total beginner as i'd never programmed before i started my degree, and i'm really stuck.

    Any help you could give me would be much appreciated

    Here is what i have so far:

    Code:
    #include <stdio.h>
    
    
    int main(void)
    
    {
    
    FILE *swbtxt;										// declare file pointer
    FILE *destination;
    
    char buffer [10000];
    
    int num;
    
    swbtxt = fopen ("swbtxt.txt","r"); 					// opens the file
    destination = fopen("dest.txt", "w");
    
    
    
    if ((swbtxt !=NULL) && (destination !=NULL))
    
    	{
    
    	num = fread(buffer,1,10000,swbtxt);					// read text
    
    	fwrite(buffer,1,num,destination);					// write text
    
    	fclose(swbtxt);										// close file
    	fclose(destination);								// close file
    
    
    	printf ("Finished: swbtxt.txt copied to dest.txt");
    	printf ("\n%d characters copied\n", num);
    
    	return 0;
    
    	}
    
    		else
    
    		{
    
    		if (swbtxt == NULL)
    
    			printf("Unable to Open swbtxt.txt\n");
    
    		if (destination == NULL)
    
    			printf ("Unable to Open dest.txt\n");
    
    		return 1;
    
    		}
    
    			
    
    
    
    
    
    }
    Im attatched the exisiting file I have to work from

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    So what have you thought on the subject?
    Write down, in English (or your own language if it's not English, if you prefer) how you would go about doing the editing process. Write it as a list of steps. Once you have a list of steps, you should be able to come up with some code to perform each of the steps.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Menu
    By Krush in forum C Programming
    Replies: 17
    Last Post: 09-01-2009, 02:34 AM
  2. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  3. Help with a pretty big C++ assignment
    By wakestudent988 in forum C++ Programming
    Replies: 1
    Last Post: 10-30-2006, 09:46 PM
  4. Replies: 1
    Last Post: 10-27-2006, 01:21 PM
  5. Stuck Between a Rock and a Hard place
    By kwigibo in forum C++ Programming
    Replies: 2
    Last Post: 05-14-2002, 05:57 PM