You're focusing too much on the little things and not seeing the big picture. The problem is very simple: display any line where the first non-whitespace character is a digit. To do that you read each line in turn, find the first non-whitespace character, and print it if it's a digit. Easy peasy:
#include <ctype.h>
#include <stdio.h>
#include <string.h>
#define WHITESPACE " \t\n\r\f\v"
int main(void)
{
FILE *in = fopen("test.txt", "r");
if (in) {
char line[BUFSIZ];
while (fgets(line, sizeof line, in)) {
char *first = line + strspn(line, WHITESPACE);
if (isdigit(*first))
fputs(line, stdout);
}
fclose(in);
}
return 0;
}
deceptikon
Challenge Accepted
3,452 posts since Jan 2012
Reputation Points: 822
Solved Threads: 473
Skill Endorsements: 57
isn't there supposed to be another file on which the new content is to written ?
I don't know, is there? My code was an example. If you want to modify it or use it as a template for a more specific solution to your problem, then do so. I actually have plenty of my own work to do, and I'm disinclined to add your work to that pile.
deceptikon
Challenge Accepted
3,452 posts since Jan 2012
Reputation Points: 822
Solved Threads: 473
Skill Endorsements: 57
But how do i get the resulting solution to a new file ?
Open a second FILE* that writes to a file and use it in place of stdout. Do you know about file I/O in C?
deceptikon
Challenge Accepted
3,452 posts since Jan 2012
Reputation Points: 822
Solved Threads: 473
Skill Endorsements: 57
Actually i am very new to programming and thus finding this a bit difficult.
All the more reason to practice. Though if you have any specific questions I'm happy to assist.
p.s. It doesn't get any easier, you just replace simple problems with more complex problems. ;)
deceptikon
Challenge Accepted
3,452 posts since Jan 2012
Reputation Points: 822
Solved Threads: 473
Skill Endorsements: 57