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; }
I was to so some of the functions (like strlwr, strcmpi, and etc) but for some reason they didn't exist in the string.h library (it kept saying the function doesn't exist). some people suggest that I make these functions myself using other libraries; but is there a way to fix the issue i'm having?
strlwr(string) and strupr(string) don't exist in standard c library string.h. you have to have a little fun and create it yourself, by using a loop that calculates the correspondent lower/uppercase char in the ASCII table and replacing it, or usinc ctype.h and tolower()/toupper() functions to convert cases. the same for strset(), strnset(), strrev(), strcmpi() and strnicmp() not defining the size of the strings results in stack overflow/stack smashing and unexpected behaviour. Examples for string to lowercase/uppercase (this doesn't accept string literals as arguments): #include char* stringToUpper(char * string){ int i = 0; while (string[i] != '\0'){ string[i] = (char)toupper(string[i]); i++; } return string; } char* stringToLower(char * string){ int i = 0; while (string[i] != '\0'){ string[i] = (char)tolower(string[i]); i++; } return string; }
I cannot find those two functions in IBM documentary for C standard libraries, although it works in Visual Studio Code. Maybe they added those function recently?
Thank you for clarifying this! It's confusing to a new programmer like me when I see things like "implicit declaration of is not valid in c99", despite it being mentioned in a tutorial video. You're a sanity saver man!
The in MacOS/Linux different of that of the Windows . strlwr(), strupr() are "non-standard", so they only exist in the Windows one, which BroCode is using.
@@toxiclucien8168 c is my first language (except shell. idk shell that much but i use linux). i'm learning c rn. i came here to copy paste the code. You?
@@SpicaSuzuki I'm currently learning C in my university so fam here to copy the code .....I have completed the whole video and now I can create any program which I'm told to....(except for the maths one coz I need to revise my maths formula for it)...but other than that I also made 3 games with Brocode help
Looked up source of didn't see them function in there so to fix had to manually write a internal code inside code, or could make my own newfunction.c file and import it there since going use it often (Put these 2 codes above your int main() not inside it) //Beginner Version strlwr() char * strlwr(char * s){ char *t = s; if (!s){ return 0; } int i = 0; while ( *t != '\0' ){ if (*t >= 'A' && *t = 'a' && *t
im little bit confused everything here works besides strset,strnset and strrev vs isnt recognizing them. i believe theyre not included in string.h and stdio.h is there a fix to it ? im writing my exam next week and were only allowed to use libraries we got shown example: bool etc aint allowed.
You don't need to remember all these functions! You can pretty much write code using your knowledge so far that accomplishes what these functions do. Knowing these functions just makes it easier for you to write code as you won't have to write new functions in your code with a specific purpose if you remember that there's a library which already does that. I.e. you won't have to create an pow(x, y) function in your program if you remember that math.h has a library with a similar function.
@@tituskace5566 So the strlwr and strupr along with some other functions listed in this video are part of the Microsoft implementation of C. Mac/linux/unix have to use different functions to alter strings. You can either use the ctype.h or code the functions yourself.
#include
#include
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;
}
you are so underated
fr
I was to so some of the functions (like strlwr, strcmpi, and etc) but for some reason they didn't exist in the string.h library (it kept saying the function doesn't exist). some people suggest that I make these functions myself using other libraries; but is there a way to fix the issue i'm having?
strlwr(string) and strupr(string) don't exist in standard c library string.h. you have to have a little fun and create it yourself, by using a loop that calculates the correspondent lower/uppercase char in the ASCII table and replacing it, or usinc ctype.h and tolower()/toupper() functions to convert cases. the same for strset(), strnset(), strrev(), strcmpi() and strnicmp()
not defining the size of the strings results in stack overflow/stack smashing and unexpected behaviour.
Examples for string to lowercase/uppercase (this doesn't accept string literals as arguments):
#include
char* stringToUpper(char * string){
int i = 0;
while (string[i] != '\0'){
string[i] = (char)toupper(string[i]);
i++;
}
return string;
}
char* stringToLower(char * string){
int i = 0;
while (string[i] != '\0'){
string[i] = (char)tolower(string[i]);
i++;
}
return string;
}
better, much better:
#include
#include
void stringToUpper(char * string){
while (*string != '\0'){
*string = (char)toupper(*string);
string++;
}
}
void stringToLower(char * string){
while (*string != '\0'){
*string = (char)tolower(*string);
string++;
}
}
int main() {
char string1[50] = "Hello";
stringToUpper(string1);
printf("To upper %s
", string1);
stringToLower(string1);
printf("To lower %s
", string1);
return 0;
}
I cannot find those two functions in IBM documentary for C standard libraries, although it works in Visual Studio Code. Maybe they added those function recently?
Thank you for clarifying this! It's confusing to a new programmer like me when I see things like "implicit declaration of is not valid in c99", despite it being mentioned in a tutorial video. You're a sanity saver man!
Thank You bro, I Wasted one hour on this.
The in MacOS/Linux different of that of the Windows . strlwr(), strupr() are "non-standard", so they only exist in the Windows one, which BroCode is using.
Nice video
Thx so much for the quality c content!
This tut was goated no cap
Thanks Coo Code, very cool
superrrr bro
keep doijng
How can strcat() make string1 bigger without malloc? And I thought that a string created using [] is constant.
first comment here.....and im already a big fan of your channel ty for sharing useful information
2nd comment
@@SpicaSuzuki which language you are learning?
@@toxiclucien8168 c is my first language (except shell. idk shell that much but i use linux). i'm learning c rn. i came here to copy paste the code. You?
@@SpicaSuzuki I'm currently learning C in my university so fam here to copy the code .....I have completed the whole video and now I can create any program which I'm told to....(except for the maths one coz I need to revise my maths formula for it)...but other than that I also made 3 games with Brocode help
@@SpicaSuzuki he's a great UA-camr...quite underrated
Holy crap thanks bro!
Who are here before exam 😂😂
Ktu?
I'm here but not before exam .
before carreer in 22's 😅
Thank you ❤️
What does case sensitivity mean?
Upper vs upper, if the first was a variable and you try to print with a second it would give and error
AWESOME!
Sir, strupr and strlwr both these functions aren't working even after including string header file. How to fix it
Looked up source of didn't see them function in there so to fix had to manually write a internal code inside code, or could make my own newfunction.c file and import it there since going use it often (Put these 2 codes above your int main() not inside it)
//Beginner Version strlwr()
char * strlwr(char * s){
char *t = s;
if (!s){
return 0;
}
int i = 0;
while ( *t != '\0' ){
if (*t >= 'A' && *t = 'a' && *t
im little bit confused everything here works besides strset,strnset and strrev vs isnt recognizing them. i believe theyre not included in string.h and stdio.h is there a fix to it ? im writing my exam next week and were only allowed to use libraries we got shown example: bool etc aint allowed.
ask chat gpt questions like this thats what im doing when my code doesnt work and idk why
@@farisraid7588 thats what i did in the end but thanks for the tip
how can we remember all these functions ?
by taking notes my dear haha
You don't need to remember all these functions! You can pretty much write code using your knowledge so far that accomplishes what these functions do. Knowing these functions just makes it easier for you to write code as you won't have to write new functions in your code with a specific purpose if you remember that there's a library which already does that. I.e. you won't have to create an pow(x, y) function in your program if you remember that math.h has a library with a similar function.
anyone knows why the result of my strcat(string1, string2) is BroCdee? im using linux mint distro
same here bro. did you find any solution
Broo😢 I came for string token where that at😭😭
most of these functions aren't working on my mac. any idea how to fix this?
Did you use the library?
@@_____Shadow_____ yes, i did. still, it didn't work.
it would help if you share which error did you get when you tried to run em
@@tituskace5566 So the strlwr and strupr along with some other functions listed in this video are part of the Microsoft implementation of C. Mac/linux/unix have to use different functions to alter strings. You can either use the ctype.h or code the functions yourself.
bro code u didn't cover strlen function
CooCode
these functions are not working in mac os
hello sir the strings functions are not working on my MacBook Pro ! what do I do ?? please help me out !!!!
😢