0% found this document useful (0 votes)
7 views2 pages

Intro Formatting

The document provides an overview of basic string and mathematical operations in C programming, including functions from String.h for string length, copying, and comparison. It also includes examples of converting integers to strings and vice versa, as well as iterating through digits of a number and finding the size of an array. The content is structured with code snippets demonstrating these functionalities.

Uploaded by

gshf57fbkz
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)
7 views2 pages

Intro Formatting

The document provides an overview of basic string and mathematical operations in C programming, including functions from String.h for string length, copying, and comparison. It also includes examples of converting integers to strings and vice versa, as well as iterating through digits of a number and finding the size of an array. The content is structured with code snippets demonstrating these functionalities.

Uploaded by

gshf57fbkz
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

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]);

You might also like