Hi, recently I've started learning to program in C
I stole "A crash course in C" from a friend ages ago and decided i better put it to use.
I'm trying to put together a little program that will read text line by line from a file, altering each line in some way( add in a char somewhere/ remove the 5 characters at the start of each line etc.) and then output it line by line to a seperate file and i've hit a bit of a brick wall.
I can load a line of text into a char. pointer with Fgets(), and i can write it out to a file with Fputs() the problem is whenever i alter the the char pointer between inputing the text to it, and outputing it to the file, i get a crash when running the program.
Hmm.. i havent been very clear, i'll try again
Basically after declaring two file pointers, I have these lines:
while (!feof(infile))
{
fgets(buffer, 1000, infile);
fputs(buffer, oufile);
}
buffer being the char pointer, and infile and oufile being the file pointers.
Thing is, i want to alter whats in buffer but whenever i put anything here:
while (!feof(infile))
{
fgets(buffer, 1000, infile);
xxxxxxxxxx
fputs(buffer, oufile);
}
i get a crash, infact what i find REALLY weird is that if i don't have the loop command in, IE just:
fgets(buffer, 1000, infile);
fputs(buffer, oufile);
I also get a crash.
Wondering if anyone could explain what I'm doing wrong, thanks in advance