Thanks to visit codestin.com
Credit goes to www.scribd.com

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

String Method

The document contains C code demonstrating string manipulation functions such as converting to lowercase, appending, copying, and comparing strings. It also includes a section on pointers, showing how to use them to reference and dereference variables. The code includes commented-out sections that illustrate various string and pointer operations.

Uploaded by

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

String Method

The document contains C code demonstrating string manipulation functions such as converting to lowercase, appending, copying, and comparing strings. It also includes a section on pointers, showing how to use them to reference and dereference variables. The code includes commented-out sections that illustrate various string and pointer operations.

Uploaded by

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

int main(){

char string1[] = "Bro";


char string2[] = "Code";

strlwr(string1); // converts a string to lowercase


//strupr(string1); // converts a string to uppercase
//strcat(string1, string2); // appends string2 to end of string1
//strncat(string1, string2, 1); // appends n characters from string2 to string1
//strcpy(string1, string2); // copy string2 to string1
//strncpy(string1, string2, 2); // copy n characters of string2 to string1

//strset(string1, '?'); //sets all characters of a string to a given character


//strnset(string1, 'x', 1); //sets first n characters of a string to a given character
//strrev(string1); //reverses a string

//int result = strlen(string1); // returns string length as int


//int result = strcmp(string1, string2); // string compare all characters
//int result = strncmp(string1, string2, 1); // string compare n characters
//int result = strcmpi(string1, string1); // string compare all (ignore case)
//int result = strnicmp(string1, string1, 1); // string compare n characters (ignore case)

printf("%s", string1);

/*
if(result == 0)
{
printf("These strings are the same");
}
else
{
printf("These strings are not the same");
}
*/

return 0;
}

Pointer
#include <stdio.h>

void printAge(int *pAge)


{
printf("You are %d years old\n", *pAge); //dereference
}
int main()
{
// pointer = a "variable-like" reference that holds a memory address to another variable, array, etc.
// some tasks are performed more easily with pointers
// * = indirection operator (value at address)

int age = 21;


int *pAge = &age;

printAge(pAge);

//printf("address of age: %p\n", &age);


//printf("value of pAge: %p\n", &pAge);
//printf("size of age: %d bytes\n", sizeof(age));
//printf("size of pAge: %d bytes\n", sizeof(pAge));
//printf("value of age: %d\n", age);
//printf("value at stored address: %d\n", *pAge); //dereferencing

return 0;
}

You might also like