Hello everyone.
i tried to write a program to eliminate nos from a file:
this is what i mean:

001 #include <QApplication>
002 #include <QPushButton>
003 int main(int argc, char *argv[])
004 {
005 QApplication app(argc, argv);
006 QPushButton *button = new QPushButton("Quit");
007 QObject::connect(button, SIGNAL(clicked()),
008 &app, SLOT(quit()));
009 button->show();
010 return app.exec();
011 }

this is the code in a book..i needed to elimiate those nos..i tried this program:

#include <stdio.h>

int main(void)
	FILE *Numbered, *Filtered;
	char fname[100];
	int c;

	printf("\nEnter the filename");
	scanf("%s", fname);

	Numbered = fopen(fname, "r");
	Filtered = fopen("FILTERED.txt", "w");

	while( (c = fgetc(Numbered)) != EOF ) {
		if(c == '\n') {
			putchar(c);// Put a \n
			//fputc(c, Filtered);
			if((c = fgetc(Numbered)) == EOF)
				return 0;
			while( c >= '0' && c <= '9' ) {
				c = fgetc(Numbered);
		//fputc(c, Filtered);


	return 0;

Its working,but going into an infinite loop! i mean its initially eliminating the nos. but getting into an infinite loop..
Can anyone please explain?
Thanks in advance.

8 Years
Discussion Span
Last Post by Ancient Dragon

I think you would have more success by reading the entire line with fgets() then just write the line into the output file starting with the 3d byte of the input buffer

char inbuf[255];
while( fgets(inbuf, sizeof(inbuf), Numbered) != NULL)
    fputs(&inbuf[2], Filtered);
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.