Hi, currently im working on a project for uni but i have no knowledge in C at all

basically what im trying to do is remove all * !"£$%^&*()- and double spaces from a text file
so far i am able to copy the text file so that im not using the original one so the user inputs what file they want to open and then specifies which name to save it as
has anyone any idea how this works
currently i have this

FILE * fpIn;
FILE * fpOut;
char a;  
char *a                        									
char array[100];
char filename[50];                      								
char filename1[50];                 								
int main(void)

printf("Enter the name of file to open ");	 

   printf("ERROR - cannot open file please try again");	
   printf ("Enter the name you wish to call the new file ");
   if (fpOut==NULL)					
   printf("Error cannot write new file! please try again");	
	printf("File has opened correctly");
   while(fgets(array, sizeof(array), fpIn))   
      fprintf(fpOut, "%s", array); 			
   return 0;

this is a massive thing for me to do as i am basically self learning in 5 days please can anyone help me

i have tried

if ((a = strchr(array, '\n')) != NULL)
*a = '\0';

please can someone help

Edited by Notme: n/a

8 Years
Discussion Span
Last Post by Dave Sinkula

Look up the function isalpha() and test each character after you read the line.

Also, see this about gets().
And see this about formatting. Yours is not very good.

once I find the code I want to remove how do I remove it?


One option would be to read in one character at the time, using e.g. fgetc(), filtering out the unwanted characters. To write to output file, you'd probably like to use the counterpart putc() .

This would narrow down the task at hand, which might be a good idea given your 5 days of programming experience.


basically what im trying to do is remove all * !"£$%^&*()- and double spaces from a text file

You could write your own iswhatever() type of function -- a linear search through "*!"£$%^&*()-" would find these. You might also look into ispunct(). The double-spaces would be a little extra.

Edited by Dave Sinkula: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.