Here's my new code:
but I have some problems in replacing a specific text. It only replaces the first character of a string.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <limits.h>
void word();
void character(FILE *fp);
void line(FILE *fp);
int main(int argc, char*argv[])
{
FILE *fp;
if(argc!=2) /*b/c there is only one file*/
{
fprintf(stderr, "%s", argv[0]);
return 1;
}
if((fp = fopen(argv[1], "r+"))==0)
{
perror("fopen");
return 1;
}
word(fp);
fclose(fp);
return 0;
}
void word(FILE *fp)
{
int c;
int space = 1;
int count = 0;
while((c=fgetc(fp))!=EOF)
{
/*checks the code if there is a space*/
if(space && !isspace(c))
{
count++;
putchar(toupper(c));
}
/*If the conditions are not met, then it will add a character*/
else
putchar(c);
/*If there is no space, it will return true*/
if(isspace(c))
space = 1;
/*If there is space, it will return false*/
else
space = 0;
}
printf("\nTotal Number: %d\t", count);
}