STRINGS - UtilityAcc/C-Notes GitHub Wiki

String is array of chars, writes in double quotes.

char *string = "STRING" pointer string points to the address of first char.

"STRING\0" Zero in the end (binary 00000000) shows the end of the string.

COMPARE STRINGS to compare the string you have to use strcompare, because you cant compare the pointers to beginning of the string

` #include <cs50.h>

#include <stdio.h>

#include <string.h>

int main(void)

{ char *s = get_string("s: ");

char *t = get_string("t: ");

if (strcmp(s, t) == 0)
{
    printf("Same\n");
}
else
{
    printf("Different\n");
}

}

`

COMPARE STRING

`

#include <cs50.h> #include <ctype.h> #include <stdio.h> #include <stdlib.h> #include <string.h>

int main(void) { char *s = get_string("s: ");

char *t = malloc(strlen(s) + 1);

strcpy(t, s);

t[0] = toupper(t[0]);

printf("s: %s\n", s);
printf("t: %s\n", t);

free(t);

}`

⚠️ **GitHub.com Fallback** ⚠️