I have a small problem after working on my program last night i found out
that C does not have any function that uppercase first character in a word.

So i have been trying to split each word in to characters and uppercase the first
word but it keeps replacing the first character whit a whitespace

It there any other way around this ?

7 Years
Discussion Span
Last Post by Narue
Featured Replies
for (i=0;i<theLength;i++)
    theString[i] = toupper(theString[i]);
return 1;

Iam trying to count the word and when it comes to the first char turn in in to upper. Iam kinda a novice this would be much easier in python and php xD


	for( ; *string != '\0'; string++)
	if(temp == ' ')

	temp = *string;

Edited by n3red: n/a


Hello n3red,
According to your code each character in the string character array will be changed to upper case. Your code will not change the first character of the string to white space.


Here is my code help xD

As you can see i successfully turn "char lines" in to lowercase characters the entire text. Now in second "for" statement i am trying to lookup each word in
"char lines" count back and if it eaquals "isspace" then go +1 character and
capitalize it. But iam getting a complile error.

Iam up to my 3rd coffe, why cant there just be a simple ucfirst function xD

Basically i need to write a function that will uppercase the first character.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

int main(){

	FILE *open;
	open = fopen("vitranc.txt","r");

	char lines[300];
	//char tmp = '\0';

		for(int i=0; lines[i]; i++){
			lines[i] = toupper(lines[i]);




Edited by n3red: n/a


Let's start with = is not the same as == in C. toupper(lines[i=0]) is also interesting, and very likely not what you wanted.


U can try dizz...

If you are using FILE...read only the first character of word convert it into uppercase using toupper and leave all the characters in a word as it is..if there is a white space " ",again convert the first character into upper case..till there is white space..
if EOF is reached...condition breaks..


Is there a better definition of problems? Can you explain what problems mean now? If you changed code, maybe if we know what the code looks like now it would be helpful, especially since we don't know what was tweaked nor how.


For anyone that may in future have this problem i have solved it the
for and if statements i did were correct thinking but i just did it a bit
wrong xD

Here is how you capitalize the first character of every word in a block of text
or a sentence etc:

char lines[300] or char lines = "some random text if its not feed'ed from a external file"

for(int i=0; lines[i]; i++){
	lines[i] = toupper(lines[i]);

Edited by n3red: n/a


The first iteration of the loop invokes undefined behavior because you're accessing lines[-1]. But good on you for figuring out what was wrong.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.