0% found this document useful (0 votes)
12 views3 pages

C Functions CheatSheet

This cheat sheet provides a comprehensive overview of various C programming functions categorized into Input/Output, String, Math, Character, Memory, File Handling, Time, and Utility functions. Each category includes function names, their descriptions, and examples of usage. It serves as a quick reference for programmers to understand and utilize these functions effectively.

Uploaded by

katedalz865
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views3 pages

C Functions CheatSheet

This cheat sheet provides a comprehensive overview of various C programming functions categorized into Input/Output, String, Math, Character, Memory, File Handling, Time, and Utility functions. Each category includes function names, their descriptions, and examples of usage. It serves as a quick reference for programmers to understand and utilize these functions effectively.

Uploaded by

katedalz865
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

■ C Programming Functions Cheat Sheet

1. Input/Output Functions ()
Function Description Example

printf() Prints text/output printf("Hello");


scanf() Reads input scanf("%d", &age);
getchar() Reads single character ch = getchar();
putchar() Prints single character putchar('A');
gets() Reads a string (unsafe) gets(str);
puts() Prints a string puts(str);

2. String Functions ()
Function Description Example

strlen(s) Length of string strlen("Hello") → 5


strcpy(dest, src) Copy string strcpy(b,a);
strcat(s1,s2) Concatenate strings strcat(a,b);
strcmp(s1,s2) Compare strings strcmp("A","B")
strchr(s,c) Find character strchr("Hello","e")
strstr(s1,s2) Find substring strstr("Hello","lo")

3. Math Functions ()
Function Description Example

sqrt(x) Square root sqrt(25) → 5


pow(x,y) Power pow(2,3) → 8
abs(x) Absolute value abs(-4) → 4
ceil(x) Round up ceil(2.3) → 3
floor(x) Round down floor(2.9) → 2
sin(x) Sine sin(0)
cos(x) Cosine cos(0)

4. Character Functions ()
Function Description Example

isalpha(c) Check letter isalpha('a')


isdigit(c) Check digit isdigit('3')
isalnum(c) Letter or number? isalnum('A')
toupper(c) Uppercase toupper('a') → 'A'
tolower(c) Lowercase tolower('Z') → 'z'

5. Memory Functions ()
Function Description Example

malloc(size) Allocate memory int *p = malloc(10*sizeof(int));


calloc(n,size) Allocate + set 0 int *p = calloc(5,sizeof(int));
realloc(p,size) Resize memory p = realloc(p,20*sizeof(int));
free(p) Free memory free(p);

6. File Handling Functions ()


Function Description Example

fopen(name,mode) Open file fopen("[Link]","w");


fclose(fp) Close file fclose(fp);
fprintf(fp,...) Write to file fprintf(fp,"Hello");
fscanf(fp,...) Read from file fscanf(fp,"%d",&x);
fgets(str,n,fp) Read string fgets(s,10,fp);
fputs(str,fp) Write string fputs("Hi",fp);

7. Time Functions ()
Function Description Example

time(NULL) Current time time_t t = time(NULL);


ctime(&t) Convert to string ctime(&t)
clock() CPU time used clock()
difftime(t1,t2) Difference between times difftime(t2,t1)

8. Utility Functions ()
Function Description Example

exit(code) Exit program exit(0);


system(cmd) Run OS command system("cls");
rand() Random number rand()%10
srand(seed) Set seed srand(time(0));

You might also like