INFO: Map the C Run-Time (CRT) Library Functions to .NET Functions

Article translations Article translations
Article ID: 313836 - View products that this article applies to.
This article was previously published under Q313836
Expand all | Collapse all

On This Page

SUMMARY

The following table lists the equivalent functions in .NET for functions in the standard C library. Locate the standard C function in the left column; the equivalent .NET function appears in the right column.

Note This is an approximate table. Some of the listed .NET functions are similar to the standard C functions, but the .NET function listed may not be an exact match. Also, if you use C++, replace the period character (.) with two colons (::).

If the function that you need is not listed in the table, refer to the More Information section of this article.

ARGUMENT ACCESS

STANDARD C FUNCTION               .NET EQUIVALENT FUNCTION
---------------------------------------------------------------------------

va_arg,va_end,va_start            ParamArray Attribute

---------------------------------------------------------------------------

BUFFER MANIPULATION

STANDARD C FUNCTIONS              .NET EQUIVALENT FUNCTIONS
---------------------------------------------------------------------------

_memccpy,memcpy                   System.Buffer.BlockCopy, 
                                  System.String.Copy

memchr,wmemchr                    System.String.CopyTo

memcmp,memicmp                    System.Collections.Arraylist.BinarySearch

memmove                           System.String.Compare, 
                                  System.String.Equals

memset                            System.Buffer.SetByte,
                                  System.Collections.Arraylist.Item

_swab                             n/a

---------------------------------------------------------------------------

BYTE CLASSIFICATION

STANDARD C FUNCTIONS              .NET EQUIVALENT FUNCTIONS
---------------------------------------------------------------------------

_isleadbyte                  n/a but see System.Globalization.CultureInfo
_ismbbalnum
_ismbbalpha
_ismbbgraph
_ismbbkalnum
_ismbbkana
_ismbbkprint
_ismbbkpunct
_ismbblead
_ismbbprint
_ismbbpunct
_ismbbtrail
_ismbslead
_ismbstrail
_mbbtype
_mbsbtype

---------------------------------------------------------------------------

CHARACTER CLASSIFICATION

STANDARD C FUNCTIONS              .NET EQUIVALENT FUNCTIONS
---------------------------------------------------------------------------

isalnum, iswalnum                System.Char.IsLetterOrDigit

_ismbcalnum                      n/a

isalpha, iswalpha, _ismbcalpha,
__isascii, iswascii              System.Char.IsLetter

iscntrl, iswcntrl                System.Char.IsControl

__iscsym, __iscsymf              System.Char.IsSymbol

isdigit, iswdigit, _ismbcdigit   System.Char.IsDigit

isgraph, iswgraph, _ismbcgraph   n/a
	
islower, iswlower, _ismbclower   System.Char.IsLower

_ismbchira                       n/a

_ismbckata                       n/a

_ismbclegal                      n/a

_ismbcl0                         n/a

_ismbcl1                         n/a

_ismbcl2                         n/a

_ismbcsymbol                     n/a

isprint, iswprint, _ismbcprint   n/a
 
ispunct, iswpunct, _ismbcpunct   System.Char.IsPunctuation

isspace, iswspace, _ismbcspace   System.Char.IsWhiteSpace

isupper, iswupper, _ismbcupper   System.Char.IsUpper

iswctype                         System.Char.GetType

isxdigit, iswxdigit              System.Char.IsNumber

mblen                            n/a

---------------------------------------------------------------------------

DATA CONVERSION

STANDARD C FUNCTIONS              .NET EQUIVALENT FUNCTIONS
---------------------------------------------------------------------------

abs                              System.Math.Abs

atof                             System.Convert.ToDouble

atoi                             System.Convert.ToInt32,
                                 System.Convert.ToUInt32

_atoi64                          System.Convert.ToInt64,
                                 System.Convert.ToUInt64

atol                             System.Convert.ToInt64,
                                 System.Convert.ToUInt64

_ecvt                            System.Convert.ToString

_fcvt                            System.Convert.ToString

_gcvt                            System.Convert.ToString

_itoa, _i64toa, _itow, _i64tow   System.Convert.ToString

labs                             System.Math.Abs

_ltoa, _ltow                     System.Convert.ToString

_mbbtombc                        n/a

_mbcjistojms                     n/a

_mbcjmstojis                     n/a

_mbctohira                       n/a

_mbctokata                       n/a

_mbctombb                        n/a

mbstowcs                         n/a

mbtowc                           n/a

strtod, wcstod                   System.Convert.ToDouble

strtol, wcstol                   System.Convert.ToInt64

strtoul, wcstoul                 System.Convert.ToUInt64

strxfrm, wcsxfrm                 System.Iformattable.ToString
__toascii

tolower, towlower, _mbctolower   System.Char.ToLower

_tolower                         System.String.ToLower

toupper, towupper, _mbctoupper   System.Char.ToUpper,
_toupper                         System.String.ToUpper

_ultoa, _ultow                   System.Convert.ToString

wcstombs                         n/a

wctomb                           n/a

_wtoi                            n/a

_wtol                            n/a

---------------------------------------------------------------------------

DEBUG

STANDARD C FUNCTIONS              .NET EQUIVALENT FUNCTIONS
---------------------------------------------------------------------------

_ASSERT, _ASSERTE                System.Diagnostics.Debug.Assert

_CrtCheckMemory                  System.Diagnostics.PerformanceCounter

_CrtDbgReport                    System.Diagnostics.Debug.Write,
                                 System.Diagnostics.Debug.Writeline,
                                 System.Diagnostics.Debug.WriteIf,
                                 System.Diagnostics.Debug.WriteLineIf

_CrtDoForAllClientObjects        n/a

_CrtDumpMemoryLeaks              n/a

_CrtIsValidHeapPointer           n/a

_CrtIsMemoryBlock                n/a

_CrtIsValidPointer               n/a

_CrtMemCheckpoint                n/a

_CrtMemDifference                n/a

_CrtMemDumpAllObjectsSince       n/a

_CrtMemDumpStatistics            System.Diagnostics.PerformanceCounter

_CrtSetAllocHook                 n/a

_CrtSetBreakAlloc                n/a

_CrtSetDbgFlag                   n/a

_CrtSetDumpClient                n/a

_CrtSetReportFile                n/a

_CrtSetReportHook                n/a

_CrtSetReportMode                n/a

_RPT[0,1,2,3,4]                  n/a

_RPTF[0,1,2,3,4]                 n/a

_calloc_dbg                      n/a

_expand_dbg                      n/a

_free_dbg                        n/a

_malloc_dbg                      n/a

_msize_dbg                       n/a

_realloc_dbg                     n/a

---------------------------------------------------------------------------

DIRECTORY CONTROL

STANDARD C FUNCTIONS              .NET EQUIVALENT FUNCTIONS
---------------------------------------------------------------------------

_chdir, _wchdir              System.Environment.CurrentDirectory

_chdrive                     System.Environment.CurrentDirectory

_getcwd, _wgetcwd            System.Environment.CurrentDirectory

_getdcwd, _wgetdcwd          System.Environment.CurrentDirectory

_getdrive                    System.Environment.CurrentDirectory

_mkdir, _wmkdir              System.IO.Directory.CreateDirectory,
                             System.IO.DirectoryInfo.CreateSubdirectory

_rmdir, _wrmdir              System.IO.Directory.Delete

searchenv, _wsearchenv       n/a

---------------------------------------------------------------------------

ERROR HANDLING

STANDARD C FUNCTIONS              .NET EQUIVALENT FUNCTIONS
---------------------------------------------------------------------------

assert macro                 n/a

_ASSERT, _ASSERTE macros     System.Diagnostics.Debug.Assert

clearerr                     n/a

_eof                         n/a

feof                         n/a

ferror                       n/a

_RPT, _RPTF macros           n/a

---------------------------------------------------------------------------

EXCEPTION HANDLING

STANDARD C FUNCTIONS              .NET EQUIVALENT FUNCTIONS
---------------------------------------------------------------------------

_set_se_translator           n/a

set_terminate                n/a

set_unexpected               n/a

terminate                    n/a

unexpected                   System.Exception

---------------------------------------------------------------------------

FILE-HANDLING ROUTINES (File Handle)

STANDARD C FUNCTIONS              .NET EQUIVALENT FUNCTIONS
---------------------------------------------------------------------------

chsize                        System.IO.Stream.SetLength,
                              System.IO.FileStream.SetLength

_filelength                   System.IO.Stream.SetLength, 
                              System.IO.FileStream.SetLength

_fstat, _fstati64             n/a

_isatty                       System.IO.Stream.CanWrite, 
                              System.IO.FileStream.CanWrite

_locking                      System.IO.Stream.Lock, 
                              System.IO.FileStream.Lock

_setmode                      see System.IO.BinaryReader, 
                              System.IO.TextReader

---------------------------------------------------------------------------

FILE-HANDLING ROUTINES (Path or File Name)

STANDARD C FUNCTIONS              .NET EQUIVALENT FUNCTIONS
---------------------------------------------------------------------------

_access, _waccess             System.IO.FileAccess

_chmod, _wchmod               System.IO.File.SetAttributes, 
                              System.Security.Permissions.FileIOPermission

_fullpath, _wfullpath         System.IO.File.Create

_get_osfhandle                n/a

_makepath, _wmakepath         System.IO.File.Create

_mktemp, _wmktemp             n/a

_open_osfhandle               System.IO.FileStream.Handle

remove, _wremove              System.IO.File.Remove

rename, _wrename              System.IO.File.Move

_splitpath, _wsplitpath       n/a

_stat, _stati64,              System.IO.File.GetAttributes, 
_wstat, _wstati64             System.IO.File.GetCreationTime,
                              System.IO.File.GetLastAccessTime, 
                              System.IO.File.GetLastWriteTime

_umask                        System.IO.File.SetAttributes

_unlink, _wunlink             System.IO.File.Remove

---------------------------------------------------------------------------

FLOATING-POINT SUPPORT

STANDARD C FUNCTIONS              .NET EQUIVALENT FUNCTIONS
---------------------------------------------------------------------------

abs                           System.Math.Abs

acos                          System.Math.Acos

asin                          System.Math.Asin

atan, atan2                   System.Math.Atan, System.Math.Atan2

atof                          System.Convert.ToInt64, 
                              System.ConvertToUInt64,
                              System.Convert.ToSingle,
                              System.Convert.ToDouble

Bessel functions

_cabs

ceil                          System.Math.Ceiling

_chgsign                      n/a

_clear87, _clearfp            n/a

_control87, _controlfp        n/a

_copysign                     n/a

cos, cosh                     System.Math.Cos, System.Math.Cosh

difftime                      System.DateTime.Subtract

div                           n/a

_ecvt                         System.Convert.ToString

exp                           System.Math.Exp

fabs                          System.Math.Abs

_fcvt                         System.Convert.ToString

_finite                       System.Double.IsInfinity

floor                         System.Math.Floor

fmod                          System.Math.IEEERemainder

_fpclass                      System.Double.IsInfinity, 
                              System.Double.IsNegativeInfinity,
                              System.Double.IsPositiveInfinity, 
                              System.Double.IsNan

_fpieee_flt                   n/a

frexp                         n/a

_gcvt                         System.Convert.ToString

_hypot                        n/a

_isnan                        System.Double.IsNan

labs                          System.Math.Abs

ldexp                         System.Math.Pow

ldiv                          n/a
  
log                           System.Math.Log

log10                         System.Math.Log10

_logb

_lrotl, _lrotr                n/a

_matherr                      n/a

__max                         System.Math.Max

__min                         System.Math.Min

modf                          n/a

nextafter
                              n/a
pow                           System.Math.Pow

printf, wprintf               System.Console.Write, 
                              System.Console.WriteLine

rand                          System.Random

_rotl, _rotr                  n/a 

_scalb                        n/a

scanf, wscanf                 System.Console.Write,
                              System.Console.WriteLine

sin, sinh                     System.Math.Sin, System.Math.Sinh

sqrt                          System.Math.Sqrt

srand                         System.Random

_status87, _statusfp          n/a

strtod                        System.Convert.ToDouble

tan, tanh                     System.Math.Tan, System.Math.Tanh

--------------------------------------------------------------------------

INPUT AND OUTPUT

STANDARD C FUNCTIONS              .NET EQUIVALENT FUNCTIONS
---------------------------------------------------------------------------

_open, fopen,                 System.IO.File.Open, 
freopen, _fsopen              System.IO.FileStream.Open

fwprintf, fwscanf,            System.Stream.Write, System.Stream.WriteLine,
fgetwc, fputwc, fgetws,       System.Console.Read, 
fputws                        System.Console.ReadLine
                              
                              
clearerr                      n/a

fclose, _fcloseall            System.IO.FileStream.Close, 
                              System.IO.Stream.Close,
                              System.IO.BinaryReader.Close,
                              System.IO.BinaryWriter.Close,
                              System.IO.TextReader.Close,
                              System.IO.TextWriter.Close,
                              System.IO.StringReader.Close,
                              System.IO.StringWriter.Close,
                              System.IO.StreamReader.Close,
                              System.IO.StreamWriter.Close

_fdopen, wfdopen              System.IO.FileStream.FileStream

feof                          System.IO.FileStream.File.Read

ferror                        n/a

fflush                        System.IO.FileStream.Flush

fgetc, fgetwc                 System.IO.FileStream.ReadByte

_fgetchar, _fgetwchar         System.IO.BinaryReader.Read, 
                              System.IO.TextReader.Read,
                              System.IO.StringReader.Read,
                              System.IO.StreamReader.Read

fgetpos, fgets, fgetws        System.IO.FileStream.Seek

_fileno                       System.IO.FileStream.Handle

_flushall                     System.IO.FileStream.Flush, 
                              System.IO.StreamWriter.Flush,
                              System.IO.TextWriter.Flush, 
                              System.IO.StringWriter.Flush,
                              System.IO.BinaryWriter.Flush

fopen, _wfopen                System.IO.File.Open

fprintf, fwprintf             System.IO.TextWriter

fputc, fputwc,_fputchar,
_fputwchar                    n/a

fputs, fputws                 n/a

fread                         n/a

freopen, _wfreopen            System.IO.File.Open

fscanf, fwscanf               n/a

fseek                         n/a

fsetpos                       System.IO.FileStream.Seek

_fsopen, _wfsopen             n/a

ftell                         n/a

fwrite                        n/a

getc, getwc                   n/a

getchar, getwchar             n/a

gets, getws                   n/a

_getw                         n/a

printf, wprintf               n/a

putc, putwc                   n/a

putchar, putwchar             n/a

puts, _putws                  n/a

_putw                         n/a

rewind                        n/a

_rmtmp                        n/a

scanf, wscanf                 n/a

setbuf                        n/a
 
_setmaxstdio                  n/a

setvbuf                       n/a

_snprintf, _snwprintf         n/a

swprintf                      n/a

sscanf, swscanf               n/a

_tempnam, _wtempnam           n/a

tmpfile                       n/a

tmpnam, _wtmpnam              n/a

ungetc, ungetwc               n/a

vfprintf, vfwprintf           n/a

vprintf, vwprintf             n/a

_vsnprintf, _vsnwprintf       n/a

vsprintf, vswprintf           n/a

---------------------------------------------------------------------------

INTERNATIONALIZATION

STANDARD C FUNCTION               .NET EQUIVALENT FUNCTION
---------------------------------------------------------------------------

Setlocale	              System.Globalization.CultureInfo

---------------------------------------------------------------------------

MEMORY ALLOCATION

STANDARD C FUNCTIONS              .NET EQUIVALENT FUNCTIONS
---------------------------------------------------------------------------

_alloca                       n/a for all

calloc

_calloc_dbg

_expand

_expand_dbg

free

_free_dbg

_get_sbh_threshold

_heapadd

_heapchk

_heapmin

_heapset

_heapwalk

malloc	new

_malloc_dbg

_msize

_msize_dbg

_query_new_handler

_query_new_mode

realloc

_realloc_dbg

_set_new_handler

_set_new_mode

_set_sbh_threshold

---------------------------------------------------------------------------

PROCESS AND ENVIRONMENT CONTROL

STANDARD C FUNCTIONS              .NET EQUIVALENT FUNCTIONS
---------------------------------------------------------------------------

abort                              n/a

assert                             System.Diagnostics.Debug.Assert

_ASSERT, _ASSERTE macros           System.Diagnostics.Debug.Assert

atexit                             System.Diagnostics.Process.AddOnExit
                                   (see Process.OnExit)

_beginthread, _beginthreadex       System.Threading.Thread.Start

_cexit,_c_exit                     System.Diagnostics.Process.CloseMainWindow

_cwait                             System.Diagnostics.Process.WaitForExit

_endthread, _endthreadex           n/a

_execl, _wexecl                    n/a

_execle, _wexecle                  n/a

_execlp, _wexeclp                  n/a

_execlpe, _wexeclpe                n/a

_execv, _wexecv                    n/a

_execve, _wexecve                  n/a

_execvp, _wexecvp                  n/a

_execvpe, _wexecvpe                System.Diagnostics.Process,
                                   System.Diagnostics.ProcessInfo

exit,_exit                         System.Diagnostics.Process.Kill

getenv, _wgetenv                   System.Environment.GetEnvironmentVariable

_getpid                            System.Diagnostics.Process.Id 

longjmp                            n/a

_onexit                            System.Diagnostics.Process.OnExit

_pclose                            n/a

perror, _wperror                   n/a

_pipe                              n/a

_popen, _wpopen                    n/a

_putenv, _wputenv                  n/a

raise                              n/a

setjmp                             n/a

signal                             n/a

_spawnl, _wspawnl                  n/a

_spawnle, _wspawnle                n/a

_spawnlp, _wspawnlp                n/a

_spawnlpe, _wspawnlpe              n/a

_spawnv, _wspawnv                  n/a

_spawnve, _wspawnve                n/a

_spawnvp, _wspawnvp                n/a

_spawnvpe, _wspawnvpe              n/a
 
system, _wsystem                   System.Diagnostics.ProcessStartInfo, 
                                   System.Diagnostics.Process

---------------------------------------------------------------------------

SEARCH AND SORTING

STANDARD C FUNCTIONS              .NET EQUIVALENT FUNCTIONS
---------------------------------------------------------------------------

bsearch                           System.Collections.ArrayList.BinarySearch

_lfind                            System.Collections.ArrayList.Contains

_lsearch                          n/a

qsort                             System.Collections.ArrayList.Sort

---------------------------------------------------------------------------

STRING MANIPULATION

STANDARD C FUNCTIONS              .NET EQUIVALENT FUNCTIONS
---------------------------------------------------------------------------

mbscoll, _mbsicoll,              System.String.Compare
_mbsncoll, _mbsnicoll

_mbsdec, _strdec, _wcsdec        n/a

_mbsinc, _strinc, _wcsinc        n/a

_mbslen                          n/a

_mbsnbcat                        n/a

_mbsnbcmp                        n/a

_mbsnbcnt                        n/a

_mbsnbcpy                        n/a

_mbsnbicmp                       n/a

_mbsnbset                        n/a

_mbsnccnt                        n/a

_mbsnextc, _strnextc, _wcsnextc  n/a

_mbsninc. _strninc, _wcsninc     n/a

_mbsspnp, _strspnp, _wcsspnp     n/a

_mbstrlen                        n/a

sprintf, _stprintf               System.Console.Write,
                                 System.Console.Writeline

strcat, wcscat, _mbscat          System.String.Concat

strchr, wcschr, _mbschr          n/a

strcmp, wcscmp, _mbscmp          n/a

strcoll, wcscoll,
_stricoll, _wcsicoll,
_strncoll, _wcsncoll             n/a

_strnicoll, _wcsnicoll           System.String.Compare

strcpy, wcscpy, _mbscpy          System.String.Copy

strcspn, wcscspn, _mbscspn       System.String.Substring

_strdup, _wcsdup, _mbsdup        System.String.Clone

strerror,_strerror               System.Exception.Message

strftime, wcsftime               System.Convert.ToString

_stricmp, _wcsicmp, _mbsicmp     System.String.Compare

strlen, wcslen,                  System.String.Length
_mbslen, _mbstrlen

_strlwr, _wcslwr, _mbslwr        System.String.ToLower

strncat, wcsncat, _mbsncat       System.String.Concat

strncmp, wcsncmp, _mbsncmp       System.String.Compare

strncpy, wcsncpy, _mbsncpy       System.String.Copy

wcsncpy, _mbsncpy                System.String.Copy

_strnicmp, _wcsnicmp, _mbsnicmp  System.String.Compare

_strnset, _wcsnset, _mbsnset     System.String.Replace

strpbrk, wcspbrk, _mbspbrk       n/a

strrchr, wcsrchr,_mbsrchr        n/a

_strrev, _wcsrev,_mbsrev         n/a

_strset, _wcsset, _mbsset        n/a

strspn, wcsspn, _mbsspn          System.String.Substring

strstr, wcsstr, _mbsstr          n/a

strtok, wcstok, _mbstok          n/a

_strupr, _wcsupr, _mbsupr        System.String.ToUpper

strxfrm, wcsxfrm                 n/a

vsprintf, _vstprint              n/a


---------------------------------------------------------------------------

SYSTEM CALLS

STANDARD C FUNCTIONS              .NET EQUIVALENT FUNCTIONS
---------------------------------------------------------------------------

_findclose                       System.IO.Directory.GetFiles,

_findfirst, _findfirsti64        System.IO.DirectoryInfo.GetFiles

_wfindfirst, _wfindfirsti64      System.IO.DirectoryInfo.GetFileSystemInfos

_findnext, _findnexti64          n/a

_wfindnext, _wfindnexti64        n/a           
                                      

---------------------------------------------------------------------------

TIME MANAGEMENT

STANDARD C FUNCTIONS              .NET EQUIVALENT FUNCTIONS
---------------------------------------------------------------------------

asctime, _wasctime               System.DateTime.ToLongDateString, 
                                 System.DateTime.ToLongTimeString,
                                 System.DateTime.ToShortDateString,
                                 System.DateTime.ToShortTimeString, 
                                 System.DateTime.ToString

clock                            n/a

ctime, _wctime                   System.DateTime.GetDateTimeFormats,
                                 System.DateTime.ToString,
                                 System.DateTime.ToLongTimeString, 
                                 System.DateTime.ToShortTimeString

difftime                         System.DateTime.Subtract

_ftime                           System.DateTime.Now

_futime                          System.IO.File.SetLastAccessTime, 
                                 System.IO.File.SetLastWriteTime,
                                 System.IO.File.SetCreationTime

gmtime                           System.DateTime.UtcNow, 
                                 System.DateTime.ToUniversalTime

localtime                        System.DateTime.ToLocalTime

mktime                           System.DateTime.DateTime

_strdate, _wstrdate              System.DateTime.Parse

strftime, wcsftime,              System.DateTime.ToLongDateString, 
_strtime, _wstrtime              System.DateTime.ToLongTimeString,  
                                 System.DateTime.ToShortDateString, 
                                 System.DateTime.ToShortTimeString, 
                                 System.DateTime.ToString

time                             n/a
           
_tzset                           n/a

_utime, _wutime                  n/a

MORE INFORMATION

If the function that you need is not listed in the previous table, then you can use PInvoke to call the standard C function. For examples of how to use PInvoke, refer to the following Microsoft Developer Network (MSDN) article:
Platform Invoke Examples

Properties

Article ID: 313836 - Last Review: November 21, 2005 - Revision: 3.3
APPLIES TO
  • Microsoft Visual C# .NET 2003 Standard Edition
  • Microsoft Visual C++ .NET 2003 Standard Edition
  • Microsoft Visual C# .NET 2002 Standard Edition
  • Microsoft Visual C++ .NET 2002 Standard Edition
Keywords: 
kbdevstudio kbinfo KB313836

Give Feedback

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com