Jump to content

Talk:Comparison of programming languages (string functions)

Page contents not supported in other languages.
From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Senor Cuete (talk | contribs) at 03:45, 10 May 2008 (C function toupper() in UpperCase). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

C function toupper() in UpperCase

This is misleading in the article. C doesn't have a function to uppercase a whole string. toupper() takes and returns an integer as its arguments, NOT strings. It's prototype:

int toupper(int c);

If c is a lowercase letter (a-z), topupper() returns the uppercase version (A-Z). Otherwise toupper() returns c unchanged. toupper() does not convert international characters (those with ASCII codes over 0x80), like ă or ç. To uppercase a whole string you need to write a function something like this:

  1. include <ctype.h> //standard C header file with the prototype of toupper()

void UpperCaseAString(char *theString)//string is a pointer to the first char of the string you want to uppercase.

{ char *myCharPtr = theString;//myCharPtr is a pointer to char - innitialize it to theString

while(*myCharPtr != '\0')//C uses-null terminated strings. *is what's pointed to by myCharPtr

   {
   *myCharPtr = toupper(*myCharPtr);
   myCharPtr ++; //myCharPtr is a pointer to type char so it will be incremented by sizeof(char).
   }

}

In C strings are essentially pointers to a character and they end where there is a NULL ('\0') character. It would be worthwhile to explain what strings are in different languages.Senor Cuete (talk) 03:41, 10 May 2008 (UTC)Senor Cuete[reply]

The 1. should appear as a pound sign and the box is put there by Wiki's text engine. I didn't type it like that.Senor Cuete (talk) 03:44, 10 May 2008 (UTC)Senor Cuete[reply]