Users Online

· Guests Online: 114

· Members Online: 0

· Total Members: 188
· Newest Member: meenachowdary055

Forum Threads

Newest Threads
No Threads created
Hottest Threads
No Threads created

Latest Articles

This C Program replaces first letter of every word with caps.

Here is source code of the C Program to replace first letter of every word with caps. The C program is successfully compiled and run on a Linux system. The program output is also shown below.

/*
* C Program to replace first letter of every word with caps
*/
#include <stdio.h>
#include <stdlib.h>

void main(int argc, char *argv[])
{
FILE *fp1;
int return_val;

if ((fp1 = fopen(argv[1],"r+")) = = NULL)
{
printf("file cant be opened");
exit(0);
}
return_val = init_cap_file(fp1);
if (return_val == 1)
{
printf("\nsuccess");
}
else
{
printf("\n failure");
}
}

int init_cap_file(FILE *fp1)
{
char ch;

ch = fgetc(fp1);
if (ch >= 97 && ch <= 122)
{
fseek(fp1, -1L, 1);
fputc(ch - 32, fp1);
}
while (ch != EOF)
{
if (ch = = ' '|| ch == '\n')
{
ch = fgetc(fp1);
if (ch >= 97 && ch <= 122)
{
fseek(fp1, -1L, 1);
fputc(ch - 32, fp1);
}
}
else
ch = fgetc(fp1);
}
return 1;
}


$ vi file5test
$ cat file5test
chandana ravella
chanikya ravella
sree lakshmi ravella
sree ramulu ravella
$ cc file5.c
$ a.out file5test

success$ cat file5test
Chandana Ravella
Chanikya Ravella
Sree Lakshmi Ravella
Sree Ramulu Ravella

Comments

No Comments have been Posted.

Post Comment

Please Login to Post a Comment.

Ratings

Rating is available to Members only.

Please login or register to vote.

No Ratings have been Posted.
Render time: 0.69 seconds
10,266,084 unique visits