Adding strings to text files..

Started by
11 comments, last by Chronoslade 22 years, 5 months ago
anybody this problem is driving me nuts......
"There is humor in everything depending on which prespective you look from."
Advertisement
    #include <stdio.h>#include <malloc.h>#define ADD_WORD "WORD"int main(){	FILE *f1, *f2;	char word[128], c;	f1=fopen("infile","r");	f2=fopen("outfile","w");	while (!feof(f1)) {		fscanf(f1,"%s",word);		fprintf(f2,"%s%s",word,ADD_WORD);		c=fgetc(f1);		if (c == '\n')			fprintf(f2,"\n");		else if (c == ' ')			fprintf(f2," ");	}	fclose(f1); fclose(f2);	return 0;}  



Edited by - Maximus on November 2, 2001 11:59:02 PM
-----------------------"When I have a problem on an Nvidia, I assume that it is my fault. With anyone else's drivers, I assume it is their fault" - John Carmack
quote:Original post by Stoffel
Just kidding. You''ve got mad regexp skills.

Not really. For one thing, I got it wrong...

sed -e "s/[^ \n\t\v\f]+/\1$STRING/g" < in.txt > out.txt

And Arild, not it isn''t: http://unxutils.sourceforge.net/

For reasons that are unclear, ''+'' appears to be broken in that version of sed, so you''d have to use:

sed -e "s/[^ \n\t\v\f][^ \n\t\v\f]*/\0$STRING/g" < in.txt > out.txt

All your bases belong to us
CoV

This topic is closed to new replies.

Advertisement