Here is my code:
Code:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define LINES 4096
/* function prototype for percentage calculation */
void percentage_calculation_numbers(char*, int, char*);
/* function prototype to count the number of characters in a string */
int countchar (char []);
/* function prototype to find the first and last letter in the word */
char find_letter (char* a, char* b);
char red;
/* function prototype to reverse the letters in the word */
char* rev(char* str);
char* reverse;
/* function so I don't have to type getch all over the place */
void MyExit(void) { system("pause"); }
/* the main program */
int numchar;
int main ()
{
/* declaring and initiaizing variables */
FILE *book;
FILE *book2;
int i;
char *filedata = malloc(4096);
char buffer[LINES];
atexit(MyExit);
i = 0;
/* open text file or report error */
book = fopen("readtext1.txt", "r+");
book2 = fopen("readtext.txt", "a+");
if(!book)
{
perror("Error: file readtext1.txt was not found or opened");
return 0;
}
if(!book2)
{
perror("Error: file readtext.txt was not found or opened");
return 0;
}
/* read from file */
while(fgets(buffer, sizeof(buffer), book)!=NULL)
{
for ( i = 0; i < 4096; ++i )
{
if ( buffer[i] == '.' )
{
buffer[i] = '\n';
fprintf(book2, "%s\n", buffer);
/* we're done, so just exit the function by returning */
return;
}
}
}
fclose(book);
fclose(book2);
return 0;
}
Here is readtext1.txt contents:
Code:
car ran.car ran. jeremy car ran ran.
Here is the contents of readtext after running the program:
Code:
car ran
car ran. jeremy car ran ran.
What I want readtex to look like is:
Code:
car ran
car ran
jeremy car ran ran
Can you just give me the code for this problem, I see you do that sometimes in some threads. If not how about a code example?