Intro formatting
. Scan formatting
. Take array of strings as input
. Check
String.h
strlen(const char *str)
Returns the length of the string (excluding the null terminator).
strcpy(char *dest, const char *src)
Copies the string src to dest (including the null terminator).
strcmp(const char *str1, const char *str2)
Compares two strings lexicographically. Returns:
● 0 if equal,
● <0 if str1 is less than str2,
● >0 if str1 is greater than str2.
Math.h, sqrt() and pow().
Convert int to string
#include <stdio.h>
int main() {
int num = 12345;
char str[20]; // Ensure the buffer is large enough
sprintf(str, "%d", num); // Convert integer to string
3
printf("String: %s\n", str);
2
return 0;
1
}
Convert String to int <stdlib.h>
#include <stdlib.h>
#include <stdio.h>
int main() {
char str[] = "-12345";
int num = atoi(str); // Convert string to integer
printf("Integer: %d\n", num);
return 0;
}
Iterate through a number
while(num != 0){
Do whatever with num %10 (gives last digit)
Num = num / 10;
}
Find size of array
int n1 = sizeof(arr1) / sizeof(arr1[0]);